f_timestamp2 timestamp without time zone,
f_json json,
f_hstore hstore,
- f_numarray numeric(7,2) [ ]
+ f_numarray numeric(7,2) [ ],
+ f_uuid uuid,
+ f_time time(0) with time zone,
+ f_time2 time without time zone
);
create table t_test2 (
FOR EACH ROW
EXECUTE PROCEDURE foo();
+ CREATE INDEX test_index1 ON t_test1 (f_varchar);
+ CREATE INDEX test_index2 ON t_test1 USING hash (f_char, f_bool);
+ CREATE INDEX test_index3 ON t_test1 USING hash (f_bigint, f_tz) WHERE f_bigint = '1' AND f_tz IS NULL;
+
alter table t_test1 add f_fk2 integer;
alter table only t_test1 add constraint c_u1 unique (f_varchar);
is( $t1->comments, 'comment on t_test1', 'Table comment exists' );
my @t1_fields = $t1->get_fields;
-is( scalar @t1_fields, 16, '16 fields in t_test1' );
+is( scalar @t1_fields, 19, '19 fields in t_test1' );
my $f1 = shift @t1_fields;
is( $f1->name, 'f_serial', 'First field is "f_serial"' );
is( $f15->is_primary_key, 0, 'Field is not PK' );
is( $f15->is_foreign_key, 0, 'Field is not FK' );
+my $f16 = shift @t1_fields;
+is( $f16->name, 'f_uuid', '16th field is "f_uuid"' );
+is( $f16->data_type, 'uuid', 'Field is a UUID' );
+is( $f16->is_nullable, 1, 'Field can be null' );
+is( $f16->size, 0, 'Size is "0"' );
+is( $f16->default_value, undef, 'Default value is "undef"' );
+is( $f16->is_primary_key, 0, 'Field is not PK' );
+is( $f16->is_foreign_key, 0, 'Field is not FK' );
+
+my $f17 = shift @t1_fields;
+is( $f17->name, 'f_time', '17th field is "f_time"' );
+is( $f17->data_type, 'time with time zone', 'Field is a time with time zone' );
+is( $f17->is_nullable, 1, 'Field can be null' );
+is( $f17->size, 0, 'Size is "0"' );
+is( $f17->default_value, undef, 'Default value is "undef"' );
+is( $f17->is_primary_key, 0, 'Field is not PK' );
+is( $f17->is_foreign_key, 0, 'Field is not FK' );
+
+my $f18 = shift @t1_fields;
+is( $f18->name, 'f_time2', '18th field is "f_time2"' );
+is( $f18->data_type, 'time without time zone', 'Field is a time without time zone' );
+is( $f18->is_nullable, 1, 'Field can be null' );
+is( $f18->size, 0, 'Size is "0"' );
+is( $f18->default_value, undef, 'Default value is "undef"' );
+is( $f18->is_primary_key, 0, 'Field is not PK' );
+is( $f18->is_foreign_key, 0, 'Field is not FK' );
+
# my $fk_ref2 = $f11->foreign_key_reference;
# isa_ok( $fk_ref2, 'SQL::Translator::Schema::Constraint', 'FK' );
# is( $fk_ref2->reference_table, 't_test2', 'FK is to "t_test2" table' );
is( $trigger->scope, 'row', "Correct scope for trigger");
is( $trigger->action, 'EXECUTE PROCEDURE foo()', "Correct action for trigger");
+# test index
+my @indices = $t1->get_indices;
+is(scalar @indices, 3, 'got three indexes');
+
+my $t1_i1 = $indices[0];
+is( $t1_i1->name, 'test_index1', 'First index is "test_index1"' );
+is( join(',', $t1_i1->fields), 'f_varchar', 'Index is on field "f_varchar"' );
+is_deeply( [ $t1_i1->options ], [], 'Index is has no options' );
+
+my $t1_i2 = $indices[1];
+is( $t1_i2->name, 'test_index2', 'Second index is "test_index2"' );
+is( join(',', $t1_i2->fields), 'f_char,f_bool', 'Index is on fields "f_char, f_bool"' );
+is_deeply( [ $t1_i2->options ], [ { using => 'hash' } ], 'Index is using hash method' );
+
+my $t1_i3 = $indices[2];
+is( $t1_i3->name, 'test_index3', 'Third index is "test_index3"' );
+is( join(',', $t1_i3->fields), 'f_bigint,f_tz', 'Index is on fields "f_bigint, f_tz"' );
+is_deeply(
+ [ $t1_i3->options ],
+ [ { using => 'hash' }, { where => "f_bigint = '1' AND f_tz IS NULL" } ],
+ 'Index is using hash method and has predicate right'
+);
+
done_testing;