dbsrgits / dbix-class-schema-loader

Official GitHub remote for git.shadowcat.co.uk DBIx-Class-Schema-Loader.git
http://dbix-class.org/
11 stars 34 forks source link

Not recognising primary key automatically set with uuid_generate_v4() in PostgreSQL database [rt.cpan.org #143291] #28

Closed rabbiveesh closed 1 year ago

rabbiveesh commented 1 year ago

Migrated from rt.cpan.org#143291 (status was 'new')

Requestors:

From bruins@hal9000.net.au on 2022-06-14 10:40:43 :

Schema Loader version 0.07049
Database: postgresql/jammy 14+238
OS: Linux ubuntu-jammy 5.15.0-25-generic
Example script: See below
Table schema:  See below

Issue: repeated warnings that the perhaps I " forgot to set its 'is_auto_increment' attribute during add_columns()?"
But Schema Loader doesn't recognise uuid_generate_v4() as setting the primary key when analysing existing table

How do I get Schema Loader to recognise that there is a default value for the primary key?

Example warning:

DBIx::Class::Storage::DBI::insert(): Missing value for primary key column 'id' on POSTGRES_TABLE - perhaps you forgot to set its 'is_auto_increment' attribute during add_columns()? Treating 'id' implicitly as an autoinc, and attempting value retrieval at PERL_CODE_LINE

Postgres Schema for Table "Invoice"

                               Table "public.invoice"
  Column  |            Type             | Collation | Nullable |      Default
----------+-----------------------------+-----------+----------+--------------------
 id       | uuid                        |           | not null | uuid_generate_v4()
 created  | timestamp without time zone |           | not null | now()
 modified | timestamp without time zone |           | not null | now()
 amount   | money                       |           | not null |
 currency | character varying(3)        |           | not null |
 is_paid  | boolean                     |           | not null | false
 user_id  | integer                     |           | not null |
Indexes:
    "invoice_pkey" PRIMARY KEY, btree (id)
    "invoice_unique_id" UNIQUE CONSTRAINT, btree (id)

Calling script (functional part).

use DBIx::Class::Schema::Loader qw/ make_schema_at /;
make_schema_at(
    'Series::Schema',
    {   components     => ["InflateColumn::DateTime"],
        debug          => 0,
        dump_directory => './lib',
        moniker_map    => \&moniker,

    },
    [ $sql_db->{db_dsn}, $sql_db->{db_username}, $sql_db->{db_password}, {} ],
);

sub moniker {
    my $table = shift;
    my $result;
    if ( $table eq 'user_table' ) {
        $result = 'User';
    }
    elsif ( $table eq 'group_table' ) {
        $result = 'Group';
    }
    else {
        $result = join q{}, map {ucfirst} split /_/, $table;
    }
    return $result;
} ## end sub moniker
xenomorpheus commented 1 year ago

This is still happening. Please help. Thanks

rabbiveesh commented 1 year ago

Hi, could you post a copy of the generated class? It would help a lot, thanks

xenomorpheus commented 1 year ago

Invoice.pm.txt To upload I had to append ".txt" due to ".pm" extension not being supported upload type.

rabbiveesh commented 1 year ago

thanks so much for helping me to fix this. This should be fixed in the latest release (0.07051); let me know if otherwise

xenomorpheus commented 1 year ago

Thank you for your efforts.