Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rabbiveesh opened this issue Nov 20, 2022 · 5 comments · Fixed by #54

Comments

@rabbiveesh
Copy link
Contributor

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
Copy link

This is still happening. Please help. Thanks

@rabbiveesh
Copy link
Contributor Author

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

@xenomorpheus
Copy link

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

@rabbiveesh
Copy link
Contributor Author

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
Copy link

Thank you for your efforts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants