Revision history for Perl extension DBIx::Class::Schema::Loader
+ - Support identity columns in PostgreSQL v10
+
0.07048_01 - 2018-02-23
- Convert from Module::Install to ExtUtils::MakeMaker + Distar (GH#17)
}
}
+ # Identity columns can't have default values
+ if ($self->dbh->{pg_server_version} >= 100000 && !exists $info->{default_value}) {
+ my $identity = $self->schema->storage->dbh->selectrow_array(<<'EOF', {}, $table->sql_name, $col);
+SELECT attidentity
+FROM pg_catalog.pg_attribute
+WHERE attrelid = ?::regclass
+AND attname = ?
+EOF
+ if ($identity) {
+ $info->{is_auto_increment} = 1;
+ $info->{extra}{generated_as_identity} = { a => 'always', d => 'by_default' }->{$identity};
+ }
+ }
+
# detect 0/1 for booleans and rewrite
if ($data_type =~ /^bool/i && exists $info->{default_value}) {
if ($info->{default_value} eq '0') {
'unique indexes are dumped correctly';
},
},
+ cond_extra => [
+ {
+ desc => 'identity columns',
+ skip => 'requires PostgreSQL 10',
+ cond => sub { $_[0]->{pg_server_version} >= 100000 },
+ create => [
+ q{
+ create table pg_loader_test13 (
+ always integer generated always as identity,
+ by_default integer generated by default as identity
+ )
+ },
+ ],
+ drop => [ qw(pg_loader_test13) ],
+ run => sub {
+ my ($schema, $monikers, $classes) = @_;
+
+ my $rsrc13 = $schema->source($monikers->{pg_loader_test13});
+ for my $col (qw(by_default always)) {
+ my $info = $rsrc13->column_info($col);
+ (my $when = uc $col) =~ tr/_/ /;
+
+ ok $info->{is_auto_increment},
+ "is_auto_increment for GENERATED $when AS IDENTITY";
+
+ is $info->{extra}{generated_as_identity}, $col,
+ "generated_as_identity for GENERATED $when AS IDENTITY";
+ }
+ },
+ },
+ ],
)->run_tests();
END {