7 use Test::More tests => 229;
8 use SQL::Translator::Schema::Constants;
10 require_ok( 'SQL::Translator' );
11 require_ok( 'SQL::Translator::Schema' );
17 my $schema = SQL::Translator::Schema->new(
21 isa_ok( $schema, 'SQL::Translator::Schema' );
23 is( $schema->name, 'foo', 'Schema name is "foo"' );
24 is( $schema->name('bar'), 'bar', 'Schema name changed to "bar"' );
26 is( $schema->database, 'MySQL', 'Schema database is "MySQL"' );
27 is( $schema->database('PostgreSQL'), 'PostgreSQL',
28 'Schema database changed to "PostgreSQL"' );
30 is( $schema->is_valid, undef, 'Schema not valid...' );
31 like( $schema->error, qr/no tables/i, '...because there are no tables' );
36 my $foo_table = $schema->add_table(name => 'foo') or warn $schema->error;
37 isa_ok( $foo_table, 'SQL::Translator::Schema::Table', 'Table "foo"' );
39 my $bar_table = SQL::Translator::Schema::Table->new( name => 'bar' ) or
40 warn SQL::Translator::Schema::Table->error;
41 $bar_table = $schema->add_table( $bar_table );
42 isa_ok( $bar_table, 'SQL::Translator::Schema::Table', 'Table "bar"' );
43 is( $bar_table->name, 'bar', 'Add table "bar"' );
45 $schema = $bar_table->schema( $schema );
46 isa_ok( $schema, 'SQL::Translator::Schema', 'Schema' );
48 is( $bar_table->name('foo'), undef,
49 q[Can't change name of table "bar" to "foo"...]);
50 like( $bar_table->error, qr/can't use table name/i,
51 q[...because "foo" exists] );
53 my $redundant_table = $schema->add_table(name => 'foo');
54 is( $redundant_table, undef, qq[Can't create another "foo" table...] );
55 like( $schema->error, qr/can't use table name/i,
56 '... because "foo" exists' );
58 $redundant_table = $schema->add_table(name => '');
59 is( $redundant_table, undef, qq[Can't add an anonymous table...] );
60 like( $schema->error, qr/No table name/i,
61 '... because it has no name ' );
63 $redundant_table = SQL::Translator::Schema::Table->new(name => '');
64 is( $redundant_table, undef, qq[Can't create an anonymous table] );
65 like( SQL::Translator::Schema::Table->error, qr/No table name/i,
66 '... because it has no name ' );
69 # $schema-> drop_table
71 my $dropped_table = $schema->drop_table($foo_table->name, cascade => 1);
72 isa_ok($dropped_table, 'SQL::Translator::Schema::Table', 'Dropped table "foo"' );
73 $schema->add_table($foo_table);
74 my $dropped_table2 = $schema->drop_table($foo_table, cascade => 1);
75 isa_ok($dropped_table2, 'SQL::Translator::Schema::Table', 'Dropped table "foo" by object' );
76 my $dropped_table3 = $schema->drop_table($foo_table->name, cascade => 1);
77 like( $schema->error, qr/doesn't exist/, qq[Can't drop non-existant table "foo"] );
79 $schema->add_table($foo_table);
83 is( $foo_table->name, 'foo', 'Table name is "foo"' );
84 is( "$foo_table", 'foo', 'Table stringifies to "foo"' );
85 is( $foo_table->is_valid, undef, 'Table "foo" is not yet valid' );
87 my $fields = $foo_table->get_fields;
88 is( scalar @{ $fields || [] }, 0, 'Table "foo" has no fields' );
89 like( $foo_table->error, qr/no fields/i, 'Error for no fields' );
91 is( $foo_table->comments, undef, 'No comments' );
96 my $person_table = $schema->add_table(
100 is( $person_table->name, 'person', 'Table name is "person"' );
101 is( $person_table->is_valid, undef, 'Table is not yet valid' );
102 is( $person_table->comments, 'foo', 'Comments = "foo"' );
103 is( join(',', $person_table->comments('bar')), 'foo,bar',
104 'Table comments = "foo,bar"' );
105 is( $person_table->comments, "foo\nbar", 'Table comments = "foo,bar"' );
110 my $f1 = $person_table->add_field(name => 'foo') or
111 warn $person_table->error;
112 isa_ok( $f1, 'SQL::Translator::Schema::Field', 'Field' );
113 is( $f1->name, 'foo', 'Field name is "foo"' );
114 is( $f1->full_name, 'person.foo', 'Field full_name is "person.foo"' );
115 is( "$f1", 'foo', 'Field stringifies to "foo"' );
116 is( $f1->data_type, '', 'Field data type is blank' );
117 is( $f1->size, 0, 'Field size is "0"' );
118 is( $f1->is_primary_key, '0', 'Field is_primary_key is false' );
119 is( $f1->is_nullable, 1, 'Field can be NULL' );
120 is( $f1->default_value, undef, 'Field default is undefined' );
121 is( $f1->comments, '', 'No comments' );
122 is( $f1->table, 'person', 'Field table is person' );
123 is( $f1->schema->database, 'PostgreSQL', 'Field schema shortcut works' );
125 my $f2 = SQL::Translator::Schema::Field->new (
128 ) or warn SQL::Translator::Schema::Field->error;
129 $f2 = $person_table->add_field( $f2 );
130 isa_ok( $f1, 'SQL::Translator::Schema::Field', 'f2' );
131 is( $f2->name, 'f2', 'Add field "f2"' );
132 is( $f2->is_nullable(0), 0, 'Field cannot be NULL' );
133 is( $f2->is_nullable(''), 0, 'Field cannot be NULL' );
134 is( $f2->is_nullable('0'), 0, 'Field cannot be NULL' );
135 is( $f2->default_value(''), '', 'Field default is empty string' );
136 is( $f2->comments, 'foo', 'Field comment = "foo"' );
137 is( join(',', $f2->comments('bar')), 'foo,bar',
138 'Field comment = "foo,bar"' );
139 is( $f2->comments, "foo\nbar", 'Field comment = "foo,bar"' );
141 $person_table = $f2->table( $person_table );
142 isa_ok( $person_table, 'SQL::Translator::Schema::Table', 'person_table' );
144 is( $f2->name('foo'), undef, q[Can't set field name of "f2" to "foo"...] );
145 like( $f2->error, qr/can't use field name/i, '...because name exists' );
147 my $redundant_field = $person_table->add_field(name => 'f2');
148 is( $redundant_field, undef, qq[Didn't create another "f2" field...] );
149 like( $person_table->error, qr/can't use field/i,
150 '... because it exists' );
152 $redundant_field = $person_table->add_field(name => '');
153 is( $redundant_field, undef, qq[Didn't add a "" field...] );
154 like( $person_table->error, qr/No field name/i,
155 '... because it has no name' );
157 $redundant_field = SQL::Translator::Schema::Field->new(name => '');
158 is( $redundant_field, undef, qq[Didn't create a "" field...] );
159 like( SQL::Translator::Schema::Field->error, qr/No field name/i,
160 '... because it has no name' );
162 my @fields = $person_table->get_fields;
163 is( scalar @fields, 2, 'Table "foo" has 2 fields' );
165 is( $fields[0]->name, 'foo', 'First field is "foo"' );
166 is( $fields[1]->name, 'f2', 'Second field is "f2"' );
167 is( join(",",$person_table->field_names), 'foo,f2',
168 'field_names is "foo,f2"' );
171 # $table-> drop_field
173 my $dropped_field = $person_table->drop_field($f2->name, cascade => 1);
174 isa_ok($dropped_field, 'SQL::Translator::Schema::Field', 'Dropped field "f2"' );
175 $person_table->add_field($f2);
176 my $dropped_field2 = $person_table->drop_field($f2, cascade => 1);
177 isa_ok($dropped_field2, 'SQL::Translator::Schema::Field', 'Dropped field "f2" by object' );
178 my $dropped_field3 = $person_table->drop_field($f2->name, cascade => 1);
179 like( $person_table->error, qr/doesn't exist/, qq[Can't drop non-existant field "f2"] );
181 $person_table->add_field($f2);
186 is( $f1->name('person_name'), 'person_name',
187 'Field name is "person_name"' );
188 is( $f1->data_type('varchar'), 'varchar', 'Field data type is "varchar"' );
189 is( $f1->size('30'), '30', 'Field size is "30"' );
190 is( $f1->is_primary_key(0), '0', 'Field is_primary_key is negative' );
192 $f1->extra( foo => 'bar' );
193 $f1->extra( { baz => 'quux' } );
194 my %extra = $f1->extra;
195 is( $extra{'foo'}, 'bar', 'Field extra "foo" is "bar"' );
196 is( $extra{'baz'}, 'quux', 'Field extra "baz" is "quux"' );
199 # New field with args
201 my $age = $person_table->add_field(
203 data_type => 'float',
206 is( $age->name, 'age', 'Field name is "age"' );
207 is( $age->data_type, 'float', 'Field data type is "float"' );
208 is( $age->size, '10,2', 'Field size is "10,2"' );
209 is( $age->size(10,2), '10,2', 'Field size still "10,2"' );
210 is( $age->size([10,2]), '10,2', 'Field size still "10,2"' );
211 is( $age->size(qw[ 10 2 ]), '10,2', 'Field size still "10,2"' );
212 is( join(':', $age->size), '10:2', 'Field size returns array' );
217 my @indices = $person_table->get_indices;
218 is( scalar @indices, 0, 'No indices' );
219 like( $person_table->error, qr/no indices/i, 'Error for no indices' );
220 my $index1 = $person_table->add_index( name => "foo" )
221 or warn $person_table->error;
222 isa_ok( $index1, 'SQL::Translator::Schema::Index', 'Index' );
223 is( $index1->name, 'foo', 'Index name is "foo"' );
225 is( $index1->is_valid, undef, 'Index name is not valid...' );
226 like( $index1->error, qr/no fields/i, '...because it has no fields' );
228 is( join(':', $index1->fields('foo,bar')), 'foo:bar',
229 'Index accepts fields');
231 is( $index1->is_valid, undef, 'Index name is not valid...' );
232 like( $index1->error, qr/does not exist in table/i,
233 '...because it used fields not in the table' );
235 is( join(':', $index1->fields(qw[foo age])), 'foo:age',
236 'Index accepts fields');
237 is( $index1->is_valid, 1, 'Index name is now valid' );
239 is( $index1->type, NORMAL, 'Index type is "normal"' );
241 my $index2 = SQL::Translator::Schema::Index->new( name => "bar" )
242 or warn SQL::Translator::Schema::Index->error;
243 $index2 = $person_table->add_index( $index2 );
244 isa_ok( $index2, 'SQL::Translator::Schema::Index', 'Index' );
245 is( $index2->name, 'bar', 'Index name is "bar"' );
247 my $indices = $person_table->get_indices;
248 is( scalar @$indices, 2, 'Two indices' );
249 is( $indices->[0]->name, 'foo', '"foo" index' );
250 is( $indices->[1]->name, 'bar', '"bar" index' );
253 # $table-> drop_index
255 my $dropped_index = $person_table->drop_index($index1->name);
256 isa_ok($dropped_index, 'SQL::Translator::Schema::Index', 'Dropped index "foo"' );
257 $person_table->add_index($index1);
258 my $dropped_index2 = $person_table->drop_index($index1);
259 isa_ok($dropped_index2, 'SQL::Translator::Schema::Index', 'Dropped index "foo" by object' );
260 is($dropped_index2->name, $index1->name, 'Dropped correct index "foo"');
261 my $dropped_index3 = $person_table->drop_index($index1->name);
262 like( $person_table->error, qr/doesn't exist/, qq[Can't drop non-existant index "foo"] );
264 $person_table->add_index($index1);
269 my @constraints = $person_table->get_constraints;
270 is( scalar @constraints, 0, 'No constraints' );
271 like( $person_table->error, qr/no constraints/i,
272 'Error for no constraints' );
273 my $constraint1 = $person_table->add_constraint( name => 'foo' )
274 or warn $person_table->error;
275 isa_ok( $constraint1, 'SQL::Translator::Schema::Constraint', 'Constraint' );
276 is( $constraint1->name, 'foo', 'Constraint name is "foo"' );
278 $fields = join(',', $constraint1->fields('age') );
279 is( $fields, 'age', 'Constraint field = "age"' );
281 $fields = $constraint1->fields;
282 ok( ref $fields[0] && $fields[0]->isa("SQL::Translator::Schema::Field"),
283 'Constraint fields returns a SQL::Translator::Schema::Field' );
285 $fields = join(',', $constraint1->fields('age,age') );
286 is( $fields, 'age', 'Constraint field = "age"' );
288 $fields = join(',', $constraint1->fields('age', 'name') );
289 is( $fields, 'age,name', 'Constraint field = "age,name"' );
291 $fields = join(',', $constraint1->fields( 'age,name,age' ) );
292 is( $fields, 'age,name', 'Constraint field = "age,name"' );
294 $fields = join(',', $constraint1->fields( 'age, name' ) );
295 is( $fields, 'age,name', 'Constraint field = "age,name"' );
297 $fields = join(',', $constraint1->fields( [ 'age', 'name' ] ) );
298 is( $fields, 'age,name', 'Constraint field = "age,name"' );
300 $fields = join(',', $constraint1->fields( qw[ age name ] ) );
301 is( $fields, 'age,name', 'Constraint field = "age,name"' );
303 $fields = join(',', $constraint1->field_names );
304 is( $fields, 'age,name', 'Constraint field_names = "age,name"' );
306 is( $constraint1->match_type, '', 'Constraint match type is empty' );
307 is( $constraint1->match_type('foo'), undef,
308 'Constraint match type rejects bad arg...' );
309 like( $constraint1->error, qr/invalid match type/i,
310 '...because it is invalid');
311 is( $constraint1->match_type('FULL'), 'full',
312 'Constraint match type = "full"' );
314 my $constraint2 = SQL::Translator::Schema::Constraint->new( name => 'bar' );
315 $constraint2 = $person_table->add_constraint( $constraint2 );
316 isa_ok( $constraint2, 'SQL::Translator::Schema::Constraint', 'Constraint' );
317 is( $constraint2->name, 'bar', 'Constraint name is "bar"' );
319 my $constraint3 = $person_table->add_constraint(
321 expression => 'foo bar',
322 ) or die $person_table->error;
323 isa_ok( $constraint3, 'SQL::Translator::Schema::Constraint', 'Constraint' );
324 is( $constraint3->type, CHECK_C, 'Constraint type is "CHECK"' );
325 is( $constraint3->expression, 'foo bar',
326 'Constraint expression is "foo bar"' );
328 my $constraints = $person_table->get_constraints;
329 is( scalar @$constraints, 3, 'Three constraints' );
330 is( $constraints->[0]->name, 'foo', '"foo" constraint' );
331 is( $constraints->[1]->name, 'bar', '"bar" constraint' );
334 # $table-> drop_constraint
336 my $dropped_con = $person_table->drop_constraint($constraint1->name);
337 isa_ok($dropped_con, 'SQL::Translator::Schema::Constraint', 'Dropped constraint "foo"' );
338 $person_table->add_constraint($constraint1);
339 my $dropped_con2 = $person_table->drop_constraint($constraint1);
340 isa_ok($dropped_con2, 'SQL::Translator::Schema::Constraint', 'Dropped constraint "foo" by object' );
341 is($dropped_con2->name, $constraint1->name, 'Dropped correct constraint "foo"');
342 my $dropped_con3 = $person_table->drop_constraint($constraint1->name);
343 like( $person_table->error, qr/doesn't exist/, qq[Can't drop non-existant constraint "foo"] );
345 $person_table->add_constraint($constraint1);
350 my $view = $schema->add_view( name => 'view1' ) or warn $schema->error;
351 isa_ok( $view, 'SQL::Translator::Schema::View', 'View' );
352 my $view_sql = 'select * from table';
353 is( $view->sql( $view_sql ), $view_sql, 'View SQL is good' );
355 my $view2 = SQL::Translator::Schema::View->new(name => 'view2') or
356 warn SQL::Translator::Schema::View->error;
357 my $check_view = $schema->add_view( $view2 );
358 is( $check_view->name, 'view2', 'Add view "view2"' );
360 my $redundant_view = $schema->add_view(name => 'view2');
361 is( $redundant_view, undef, qq[Didn't create another "view2" view...] );
362 like( $schema->error, qr/can't create view/i, '... because it exists' );
365 # $schema-> drop_view
367 my $dropped_view = $schema->drop_view($view->name);
368 isa_ok($dropped_view, 'SQL::Translator::Schema::View', 'Dropped view "view1"' );
369 $schema->add_view($view);
370 my $dropped_view2 = $schema->drop_view($view);
371 isa_ok($dropped_view2, 'SQL::Translator::Schema::View', 'Dropped view "view1" by object' );
372 is($dropped_view2->name, $view->name, 'Dropped correct view "view1"');
373 my $dropped_view3 = $schema->drop_view($view->name);
374 like( $schema->error, qr/doesn't exist/, qq[Can't drop non-existant view "view1"] );
376 $schema->add_view($view);
381 my $bad_table = $schema->get_table;
382 like( $schema->error, qr/no table/i, 'Error on no arg to get_table' );
384 $bad_table = $schema->get_table('baz');
385 like( $schema->error, qr/does not exist/i,
386 'Error on bad arg to get_table' );
388 my $bad_view = $schema->get_view;
389 like( $schema->error, qr/no view/i, 'Error on no arg to get_view' );
391 $bad_view = $schema->get_view('bar');
392 like( $schema->error, qr/does not exist/i,
393 'Error on bad arg to get_view' );
395 my $good_table = $schema->get_table('foo');
396 isa_ok( $good_table, 'SQL::Translator::Schema::Table', 'Table "foo"' );
398 my $good_view = $schema->get_view('view1');
399 isa_ok( $good_view, 'SQL::Translator::Schema::View', 'View "view1"' );
400 is( $view->sql( $view_sql ), $view_sql, 'View SQL is good' );
405 my @tables = $schema->get_tables;
406 is( scalar @tables, 3, 'Found 2 tables' );
408 my @views = $schema->get_views;
409 is( scalar @views, 2, 'Found 1 view' );
414 # Test ability to introspect some values
417 my $s = SQL::Translator::Schema->new(
419 database => 'PostgreSQL',
421 my $t = $s->add_table( name => 'person' ) or warn $s->error;
422 my $f = $t->add_field( name => 'person_id' ) or warn $t->error;
423 $f->data_type('serial');
425 my $c = $t->add_constraint(
427 fields => 'person_id',
430 is( $f->is_primary_key, 1, 'Field is PK' );
431 is( $f->is_auto_increment, 1, 'Field is auto inc' );
435 # FK constraint validity
438 my $s = SQL::Translator::Schema->new;
439 my $t = $s->add_table( name => 'person' ) or warn $s->error;
440 my $c = $t->add_constraint or warn $t->error;
442 is( $c->is_valid, undef, 'Constraint on "person" not valid...');
443 like( $c->error, qr/no type/i, '...because it has no type' );
445 is( $c->type( FOREIGN_KEY ), FOREIGN_KEY, 'Constraint type now a FK' );
447 is( $c->is_valid, undef, 'Constraint on "person" not valid...');
448 like( $c->error, qr/no fields/i, '...because it has no fields' );
450 is( join('', $c->fields('foo')), 'foo', 'Fields now = "foo"' );
452 is( $c->is_valid, undef, 'Constraint on "person" not valid...');
453 like( $c->error, qr/non-existent field/i,
454 q[...because field "foo" doesn't exist] );
456 my $fk = $t->add_field( name => 'pet_id' );
457 is( $fk->name, 'pet_id', 'Added field "pet_id"' );
458 is( join('', $c->fields('pet_id')), 'pet_id', 'Fields now = "pet_id"' );
460 $t->add_field( name => 'f1' );
461 $t->add_field( name => 'f2' );
462 is( join(',', $c->fields('f1,f2')), 'f1,f2', 'Fields now = "f1,f2"' );
463 is( $c->is_valid, undef, 'Constraint on "person" not valid...');
464 like( $c->error, qr/only one field/i,
465 q[...because too many fields for FK] );
469 is( $c->is_valid, undef, 'Constraint on "person" not valid...');
470 like( $c->error, qr/no reference table/i,
471 q[...because there's no reference table] );
473 is( $c->reference_table('foo'), 'foo', 'Reference table now = "foo"' );
474 is( $c->is_valid, undef, 'Constraint on "person" not valid...');
475 like( $c->error, qr/no table named/i,
476 q[...because reference table "foo" doesn't exist] );
478 my $t2 = $s->add_table( name => 'pet' );
479 is( $t2->name, 'pet', 'Added "pet" table' );
481 is( $c->reference_table('pet'), 'pet', 'Reference table now = "pet"' );
483 is( $c->is_valid, undef, 'Constraint on "person" not valid...');
484 like( $c->error, qr/no reference fields/i,
485 q[...because there're no reference fields]);
487 is( join('', $c->reference_fields('pet_id')), 'pet_id',
488 'Reference fields = "pet_id"' );
490 is( $c->is_valid, undef, 'Constraint on "person" not valid...');
491 like( $c->error, qr/non-existent field/i,
492 q[...because there's no "pet_id" field in "pet"]);
494 my $pet_id = $t2->add_field( name => 'pet_id' );
495 is( $pet_id->name, 'pet_id', 'Added field "pet_id"' );
497 is( $c->is_valid, 1, 'Constraint now valid' );
501 # $table->primary_key test
504 my $s = SQL::Translator::Schema->new;
505 my $t = $s->add_table( name => 'person' );
507 is( $t->primary_key, undef, 'No primary key' );
509 is( $t->primary_key('person_id'), undef,
510 q[Can't make PK on "person_id"...] );
511 like( $t->error, qr/invalid field/i, "...because it doesn't exist" );
513 $t->add_field( name => 'person_id' );
514 my $c = $t->primary_key('person_id');
516 isa_ok( $c, 'SQL::Translator::Schema::Constraint', 'Constraint' );
518 is( join('', $c->fields), 'person_id', 'Constraint now on "person_id"' );
520 $t->add_field( name => 'name' );
521 $c = $t->primary_key('name');
522 is( join(',', $c->fields), 'person_id,name',
523 'Constraint now on "person_id" and "name"' );
525 is( scalar @{ $t->get_constraints }, 1, 'Found 1 constraint' );
532 my $s = SQL::Translator::Schema->new;
533 my $t1 = $s->add_table( name => 'person' );
534 my $t2 = $s->add_table( name => 'pet' );
535 $t1->add_field( name => 'id' );
536 my $c1 = $t1->primary_key( 'id' ) or warn $t1->error;
537 is( $c1->type, PRIMARY_KEY, 'Made "person_id" PK on "person"' );
539 $t2->add_field( name => 'person_id' );
540 my $c2 = $t2->add_constraint(
542 fields => 'person_id',
543 reference_table => 'person',
546 is( join('', $c2->reference_fields), 'id', 'FK found PK "person.id"' );
553 my $s = SQL::Translator::Schema->new( name => 'ViewTest' );
554 my $name = 'foo_view';
555 my $sql = 'select name, age from person';
556 my $fields = 'name, age';
557 my $v = $s->add_view(
564 isa_ok( $v, 'SQL::Translator::Schema::View', 'View' );
565 isa_ok( $v->schema, 'SQL::Translator::Schema', 'Schema' );
566 is( $v->schema->name, 'ViewTest', qq[Schema name is "'ViewTest'"] );
567 is( $v->name, $name, qq[Name is "$name"] );
568 is( $v->sql, $sql, qq[Name is "$sql"] );
569 is( join(':', $v->fields), 'name:age', qq[Fields are "$fields"] );
571 my @views = $s->get_views;
572 is( scalar @views, 1, 'Number of views is 1' );
574 my $v1 = $s->get_view( $name );
575 isa_ok( $v1, 'SQL::Translator::Schema::View', 'View' );
576 is( $v1->name, $name, qq[Name is "$name"] );
583 my $s = SQL::Translator::Schema->new(name => 'TrigTest');
584 $s->add_table(name=>'foo') or die "Couldn't create table: ", $s->error;
585 my $name = 'foo_trigger';
586 my $perform_action_when = 'after';
587 my $database_event = 'insert';
588 my $on_table = 'foo';
589 my $action = 'update modified=timestamp();';
590 my $t = $s->add_trigger(
592 perform_action_when => $perform_action_when,
593 database_event => $database_event,
594 on_table => $on_table,
598 isa_ok( $t, 'SQL::Translator::Schema::Trigger', 'Trigger' );
599 isa_ok( $t->schema, 'SQL::Translator::Schema', 'Schema' );
600 is( $t->schema->name, 'TrigTest', qq[Schema name is "'TrigTest'"] );
601 is( $t->name, $name, qq[Name is "$name"] );
602 is( $t->perform_action_when, $perform_action_when,
603 qq[Perform action when is "$perform_action_when"] );
604 is( $t->database_event, $database_event,
605 qq[Database event is "$database_event"] );
606 isa_ok( $t->table, 'SQL::Translator::Schema::Table', qq[table is a Table"] );
607 is( $t->action, $action, qq[Action is "$action"] );
609 my @triggs = $s->get_triggers;
610 is( scalar @triggs, 1, 'Number of triggers is 1' );
612 my $t1 = $s->get_trigger( $name );
613 isa_ok( $t1, 'SQL::Translator::Schema::Trigger', 'Trigger' );
614 is( $t1->name, $name, qq[Name is "$name"] );
617 # $schema-> drop_trigger
619 my $dropped_trig = $s->drop_trigger($t->name);
620 isa_ok($dropped_trig, 'SQL::Translator::Schema::Trigger', 'Dropped trigger "foo_trigger"' );
622 my $dropped_trig2 = $s->drop_trigger($t);
623 isa_ok($dropped_trig2, 'SQL::Translator::Schema::Trigger', 'Dropped trigger "foo_trigger" by object' );
624 is($dropped_trig2->name, $t->name, 'Dropped correct trigger "foo_trigger"');
625 my $dropped_trig3 = $s->drop_trigger($t->name);
626 like( $s->error, qr/doesn't exist/, qq[Can't drop non-existant trigger "foo_trigger"] );
635 my $s = SQL::Translator::Schema->new( name => 'ProcTest' );
636 my $name = 'foo_proc';
637 my $sql = 'select foo from bar';
638 my $parameters = 'foo, bar';
640 my $comments = 'Go Sox!';
641 my $p = $s->add_procedure(
644 parameters => $parameters,
646 comments => $comments,
649 isa_ok( $p, 'SQL::Translator::Schema::Procedure', 'Procedure' );
650 isa_ok( $p->schema, 'SQL::Translator::Schema', 'Schema' );
651 is( $p->schema->name, 'ProcTest', qq[Schema name is "'ProcTest'"] );
652 is( $p->name, $name, qq[Name is "$name"] );
653 is( $p->sql, $sql, qq[SQL is "$sql"] );
654 is( join(',', $p->parameters), 'foo,bar', qq[Params = 'foo,bar'] );
655 is( $p->comments, $comments, qq[Comments = "$comments"] );
657 my @procs = $s->get_procedures;
658 is( scalar @procs, 1, 'Number of procedures is 1' );
660 my $p1 = $s->get_procedure( $name );
661 isa_ok( $p1, 'SQL::Translator::Schema::Procedure', 'Procedure' );
662 is( $p1->name, $name, qq[Name is "$name"] );
665 # $schema-> drop_procedure
667 my $dropped_proc = $s->drop_procedure($p->name);
668 isa_ok($dropped_proc, 'SQL::Translator::Schema::Procedure', 'Dropped procedure "foo_proc"' );
669 $s->add_procedure($p);
670 my $dropped_proc2 = $s->drop_procedure($p);
671 isa_ok($dropped_proc2, 'SQL::Translator::Schema::Procedure', 'Dropped procedure "foo_proc" by object' );
672 is($dropped_proc2->name, $p->name, 'Dropped correct procedure "foo_proc"');
673 my $dropped_proc3 = $s->drop_procedure($p->name);
674 like( $s->error, qr/doesn't exist/, qq[Can't drop non-existant procedure "foo_proc"] );
676 $s->add_procedure($p);