Commit | Line | Data |
---|---|---|
d3fad399 | 1 | #!/usr/local/bin/perl |
2 | # vim: set ft=perl: | |
3 | ||
4 | use strict; | |
5 | use Test::More tests => 2; | |
6 | use Test::Differences; | |
7 | use SQL::Translator; | |
e1742702 | 8 | use FindBin '$Bin'; |
d3fad399 | 9 | |
e1742702 | 10 | my $yaml = q/--- #YAML:1.0 |
af53e4ec | 11 | schema: |
e93454af | 12 | procedures: {} |
13 | tables: | |
e1742702 | 14 | person: |
e93454af | 15 | comments: '' |
0919510d | 16 | constraints: |
17 | - deferrable: 1 | |
18 | expression: '' | |
19 | fields: | |
20 | - person_id | |
21 | match_type: '' | |
22 | name: '' | |
23 | on_delete: '' | |
24 | on_update: '' | |
25 | options: [] | |
26 | reference_fields: ~ | |
27 | reference_table: '' | |
28 | type: PRIMARY KEY | |
29 | - deferrable: 1 | |
30 | expression: '' | |
31 | fields: | |
32 | - name | |
33 | match_type: '' | |
34 | name: u_name | |
35 | on_delete: '' | |
36 | on_update: '' | |
37 | options: [] | |
38 | reference_fields: ~ | |
39 | reference_table: '' | |
40 | type: UNIQUE | |
e93454af | 41 | fields: |
e1742702 | 42 | age: |
43 | data_type: integer | |
44 | default_value: ~ | |
45 | extra: {} | |
46 | is_nullable: 1 | |
47 | is_primary_key: 0 | |
48 | is_unique: 0 | |
49 | name: age | |
50 | order: 3 | |
51 | size: | |
52 | - 0 | |
53 | description: | |
54 | data_type: text | |
55 | default_value: ~ | |
56 | extra: {} | |
57 | is_nullable: 1 | |
58 | is_primary_key: 0 | |
59 | is_unique: 0 | |
60 | name: description | |
61 | order: 6 | |
62 | size: | |
63 | - 0 | |
64 | iq: | |
65 | data_type: tinyint | |
66 | default_value: 0 | |
67 | extra: {} | |
68 | is_nullable: 1 | |
69 | is_primary_key: 0 | |
70 | is_unique: 0 | |
71 | name: iq | |
72 | order: 5 | |
73 | size: | |
74 | - 0 | |
75 | name: | |
e93454af | 76 | data_type: varchar |
e1742702 | 77 | default_value: ~ |
e93454af | 78 | extra: {} |
79 | is_nullable: 0 | |
80 | is_primary_key: 0 | |
e1742702 | 81 | is_unique: 1 |
82 | name: name | |
e93454af | 83 | order: 2 |
84 | size: | |
e1742702 | 85 | - 20 |
86 | person_id: | |
87 | data_type: INTEGER | |
e93454af | 88 | default_value: ~ |
89 | extra: {} | |
90 | is_nullable: 0 | |
91 | is_primary_key: 1 | |
92 | is_unique: 0 | |
e1742702 | 93 | name: person_id |
e93454af | 94 | order: 1 |
95 | size: | |
e1742702 | 96 | - 0 |
97 | weight: | |
98 | data_type: double | |
99 | default_value: ~ | |
100 | extra: {} | |
101 | is_nullable: 1 | |
102 | is_primary_key: 0 | |
103 | is_unique: 0 | |
104 | name: weight | |
105 | order: 4 | |
106 | size: | |
e93454af | 107 | - 11 |
e1742702 | 108 | - 2 |
0919510d | 109 | indices: [] |
e1742702 | 110 | name: person |
111 | options: [] | |
112 | order: 1 | |
113 | pet: | |
114 | comments: '' | |
0919510d | 115 | constraints: |
116 | - deferrable: 1 | |
117 | expression: '' | |
118 | fields: ~ | |
119 | match_type: '' | |
120 | name: '' | |
121 | on_delete: '' | |
122 | on_update: '' | |
123 | options: [] | |
124 | reference_fields: ~ | |
125 | reference_table: '' | |
126 | type: CHECK | |
127 | - deferrable: 1 | |
128 | expression: '' | |
129 | fields: | |
130 | - pet_id | |
131 | - person_id | |
132 | match_type: '' | |
133 | name: '' | |
134 | on_delete: '' | |
135 | on_update: '' | |
136 | options: [] | |
137 | reference_fields: ~ | |
138 | reference_table: '' | |
139 | type: PRIMARY KEY | |
e1742702 | 140 | fields: |
141 | age: | |
142 | data_type: int | |
e93454af | 143 | default_value: ~ |
144 | extra: {} | |
145 | is_nullable: 1 | |
146 | is_primary_key: 0 | |
147 | is_unique: 0 | |
e1742702 | 148 | name: age |
149 | order: 10 | |
150 | size: | |
151 | - 0 | |
152 | name: | |
153 | data_type: varchar | |
154 | default_value: ~ | |
155 | extra: {} | |
156 | is_nullable: 1 | |
157 | is_primary_key: 0 | |
158 | is_unique: 0 | |
159 | name: name | |
160 | order: 9 | |
161 | size: | |
162 | - 30 | |
163 | person_id: | |
164 | data_type: int | |
165 | default_value: ~ | |
166 | extra: {} | |
167 | is_nullable: 0 | |
168 | is_primary_key: 1 | |
169 | is_unique: 0 | |
170 | name: person_id | |
171 | order: 8 | |
172 | size: | |
173 | - 0 | |
174 | pet_id: | |
175 | data_type: int | |
176 | default_value: ~ | |
177 | extra: {} | |
178 | is_nullable: 0 | |
179 | is_primary_key: 1 | |
180 | is_unique: 0 | |
181 | name: pet_id | |
182 | order: 7 | |
e93454af | 183 | size: |
184 | - 0 | |
0919510d | 185 | indices: [] |
e1742702 | 186 | name: pet |
e93454af | 187 | options: [] |
e1742702 | 188 | order: 2 |
189 | triggers: | |
190 | after: | |
191 | action: | |
192 | for_each: ~ | |
193 | steps: | |
194 | - update name=name | |
195 | when: ~ | |
196 | database_event: insert | |
197 | fields: ~ | |
198 | name: after | |
199 | on_table: ~ | |
200 | order: 1 | |
201 | perform_action_when: ~ | |
202 | views: | |
203 | person_pet: | |
204 | fields: ~ | |
205 | name: person_pet | |
af53e4ec | 206 | order: 1 |
e1742702 | 207 | sql: | |
208 | select pr.person_id, pr.name as person_name, pt.name as pet_name | |
209 | from person pr, pet pt | |
210 | where person.person_id=pet.pet_id | |
211 | /; | |
d3fad399 | 212 | |
d3fad399 | 213 | my $tr = SQL::Translator->new( |
e1742702 | 214 | parser => 'SQLite', |
215 | producer => 'YAML', | |
216 | filename => "$Bin/data/sqlite/create.sql", | |
d3fad399 | 217 | ); |
218 | ||
e1742702 | 219 | my $out; |
220 | ok( $out = $tr->translate, 'Translate SQLite to YAML' ); | |
221 | eq_or_diff( $out, $yaml, 'YAML matches expected' ); |