bliako has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monk Programmers
In a previous question (Is it worth migrating from MySQL to MariaDB?) I was asking if it is a good move to switch from MySQL to MariaDB. And the consensus was Yes. However. I forgot to mention one crucial part of my settings: that I am relying heavily on DBIx::Class which has no loader for MariaDB. The "solutions" are 2:
in the custom-code part of the Schema.pm auto-generated file (by DBIx). This sounds straightforward and DBIx converts my SQL to packages OK. The only problem (so far) is that the generated files do not contain a set_primary_key() for those tables which my SQL code explicitly declares one column to be the PK. Instead it has a:
__PACKAGE__->add_unique_constraint( "PRIMARY", ["id"] );
This should work but it doesn't! Because further on, DBIx::Class complains with:
Error: {UNKNOWN}: DBIx::Class::ResultSource::_pri_cols_or_die(): Oper +ation requires a primary key to be declared on 'MyApp::Schema::XYZ' v +ia set_primary_key ...
My hack was to add a __PACKAGE__->set_primary_key("id"); in the custom-code part of the auto-generated schema file for each table that needs it.
Fine! This creates the schema files and finally connects to DB. BUT my tests fail with surreal output. The culprit, I found out hours later, is that none of my tables' PK is ... auto_increment'ed (as it was stated in my SQL code) !!!!!!!!!
Currently, this directive is set in said file, like so:
# when I am using DBI:mysql ... __PACKAGE__->add_columns( "id", { "is_auto_increment" => "1", "data_type" => "mediumint", ... } ); __PACKAGE__->set_primary_key("id");
The auto_increment directive is currently missing from my DBIx::Class auto-generated files. From a diagonal look in the documentation I did not see how to modify these directives for each column in the custom-code part of the auto-generated files. I did try to re-issue a __PACKAGE__->add_columns(...) in the custom-code part hoping that it will modify it but I did not see any change.
To summarise, I am looking for a solution in using DBD::MariaDB (and not DBD::mysql) with DBIx::Class with primary keys declared explicitly and also to be auto-incremented if that is what my SQL states.
I have filed an issue with DBIx::Class::Storage::DBI::MariaDB at https://github.com/Siemplexus/DBIx-Class-Storage-DBI-MariaDB/issues/4 and plan to do the same with DBIx::Class.
bw, bliako
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBD::MariaDB + DBIx::Class = woes
by NERDVANA (Priest) on Nov 07, 2023 at 19:01 UTC | |
|
Re: DBD::MariaDB + DBIx::CLass = woes
by choroba (Cardinal) on Nov 07, 2023 at 12:09 UTC | |
by bliako (Abbot) on Nov 07, 2023 at 12:35 UTC | |
by choroba (Cardinal) on Nov 07, 2023 at 15:02 UTC | |
by bliako (Abbot) on Nov 07, 2023 at 15:20 UTC | |
by 1nickt (Canon) on Nov 07, 2023 at 12:33 UTC | |
|
Re: DBD::MariaDB + DBIx::Class = woes
by rbrew (Novice) on May 08, 2024 at 13:10 UTC | |
by bliako (Abbot) on May 08, 2024 at 17:09 UTC | |
by rbrew (Novice) on May 11, 2024 at 13:08 UTC | |
by NERDVANA (Priest) on May 13, 2024 at 23:04 UTC | |
by bliako (Abbot) on May 13, 2024 at 13:54 UTC | |
by bliako (Abbot) on Sep 20, 2024 at 20:22 UTC |