-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy path24yaml.t
More file actions
255 lines (251 loc) · 5.58 KB
/
Copy path24yaml.t
File metadata and controls
255 lines (251 loc) · 5.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
use warnings;
use strict;
use Test::More;
use Test::Exception;
use Test::SQL::Translator qw(maybe_plan);
use SQL::Translator;
use FindBin '$Bin';
BEGIN {
maybe_plan(2, 'SQL::Translator::Parser::SQLite', 'SQL::Translator::Producer::YAML');
}
my $sqlt_version = $SQL::Translator::VERSION;
use YAML::Any qw(Load);
my $yaml = Load(<<YAML);
---
schema:
procedures: {}
tables:
person:
constraints:
- deferrable: 1
expression: ''
fields:
- person_id
match_type: ''
name: ''
on_delete: ''
on_update: ''
options: []
reference_fields: []
reference_table: ''
type: PRIMARY KEY
- deferrable: 1
expression: ''
fields:
- name
match_type: ''
name: u_name
on_delete: ''
on_update: ''
options: []
reference_fields: []
reference_table: ''
type: UNIQUE
fields:
age:
data_type: integer
default_value: ~
is_nullable: 1
is_primary_key: 0
is_unique: 0
name: age
order: 3
size:
- 0
description:
data_type: text
default_value: ~
is_nullable: 1
is_primary_key: 0
is_unique: 0
name: description
order: 6
size:
- 0
iq:
data_type: tinyint
default_value: 0
is_nullable: 1
is_primary_key: 0
is_unique: 0
name: iq
order: 5
size:
- 0
name:
data_type: varchar
default_value: ~
is_nullable: 0
is_primary_key: 0
is_unique: 1
name: name
order: 2
size:
- 20
person_id:
comments:
- field comment 1
- field comment 2
data_type: INTEGER
default_value: ~
is_auto_increment: 1
is_nullable: 0
is_primary_key: 1
is_unique: 0
name: person_id
order: 1
size:
- 0
extra:
auto_increment_type: monotonic
weight:
data_type: double
default_value: ~
is_nullable: 1
is_primary_key: 0
is_unique: 0
name: weight
order: 4
size:
- 11
- 2
indices: []
name: person
options: []
order: 1
comments :
- table comment 1
- table comment 2
- table comment 3
pet:
constraints:
- deferrable: 1
expression: ''
fields: []
match_type: ''
name: ''
on_delete: ''
on_update: ''
options: []
reference_fields: []
reference_table: ''
type: CHECK
- deferrable: 1
expression: ''
fields:
- pet_id
- person_id
match_type: ''
name: ''
on_delete: ''
on_update: ''
options: []
reference_fields: []
reference_table: ''
type: PRIMARY KEY
- deferrable: 1
expression: ''
fields:
- person_id
match_type: ''
name: ''
on_delete: ''
on_update: ''
options: []
reference_fields:
- person_id
reference_table: person
type: FOREIGN KEY
fields:
age:
data_type: int
default_value: ~
is_nullable: 1
is_primary_key: 0
is_unique: 0
name: age
order: 4
size:
- 0
name:
data_type: varchar
default_value: ~
is_nullable: 1
is_primary_key: 0
is_unique: 0
name: name
order: 3
size:
- 30
person_id:
data_type: int
default_value: ~
is_nullable: 0
is_primary_key: 1
is_unique: 0
name: person_id
order: 2
size:
- 0
pet_id:
data_type: int
default_value: ~
is_nullable: 0
is_primary_key: 1
is_unique: 0
name: pet_id
order: 1
size:
- 0
indices: []
name: pet
options: []
order: 2
triggers:
pet_trig:
action:
for_each: ~
steps:
- update pet set name=name
when: ~
database_events:
- insert
fields: ~
name: pet_trig
on_table: pet
order: 1
perform_action_when: after
scope: row
views:
person_pet:
fields: []
name: person_pet
order: 1
sql: |
select pr.person_id, pr.name as person_name, pt.name as pet_name
from person pr, pet pt
where person.person_id=pet.pet_id
translator:
add_drop_table: 0
filename: ~
no_comments: 0
parser_args: {}
parser_type: SQL::Translator::Parser::SQLite
producer_args: {}
producer_type: SQL::Translator::Producer::YAML
show_warnings: 0
trace: 0
version: $sqlt_version
YAML
my $file = "$Bin/data/sqlite/create.sql";
open FH, "<$file" or die "Can't read '$file': $!\n";
local $/;
my $data = <FH>;
my $tr = SQL::Translator->new(
parser => 'SQLite',
producer => 'YAML',
data => $data,
);
my $out;
lives_ok { $out = Load($tr->translate) } 'Translate SQLite to YAML';
is_deeply($out, $yaml, 'YAML matches expected');