X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FPg.pm;fp=lib%2FDBIx%2FClass%2FSchema%2FLoader%2FDBI%2FPg.pm;h=aaa2c9213c185fa6248607d7e4a8a8d020f00bbd;hb=013d8a3d7f3bf2e7b59a4655250160f66fc56846;hp=78e8a9f6ef1501cc0111074142469c829a2af0b8;hpb=40f9888acbbad69d5bf101e46eaef45c85ce2b79;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm index 78e8a9f..aaa2c92 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/Pg.pm @@ -329,6 +329,20 @@ EOF } } + # 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') {