DBIx-Class-Migration icon indicating copy to clipboard operation
DBIx-Class-Migration copied to clipboard

Support for multiple schemas on same server?

Open jbakerdev opened this issue 5 years ago • 0 comments

Hi folks - thanks for all your work on this package. I'm trying to integrate this with an existing app that piggy-backs off of a bugzilla server/database, but has additional app-specific database schemas. Not sure if I'm doing certain things incorrectly, but I'm beginning to wonder if the code wasn't intended for my use case.

My situation: Bugzilla server with fairly extensive customer-designed apps/addons

  • MySQL 5.5 server
    • Bugzilla schema for all standard bugzilla functionality (aka "bugzilla")
    • Additional schema 1 for in-house addon 1 (aka "addon1")
    • Additional schema 2 for in-house addon 1 (aka "addon2")
  • Using DBIx::Class, with result classes set up per the recommendations in DBIx::Class::Manual::FAQ:
If your database server allows you to run queries across multiple databases at once, then so can DBIx::Class. 
All you need to do is make sure you write the database name as part of the table call. Eg:

    __PACKAGE__->table('mydb.mytablename');

And load all the Result classes for both / all databases by calling "load_namespaces" in DBIx::Class::Schema.

And my classes are organized like this:

  • MyApp
    • Schema
      • Result
        • Bugzilla
          • Profile.pm
        • Addon1
          • Widget.pm
        • Addon2
          • Thingy.pm

Issues / Questions

  • When running "dbic-migration" commands against my develoipment server (not the sandbox, but also mysql) what should I use for the "database=" portion of the dsn?
    • I have been assuming that I have to pick a "main" schema (where the versions table would live)? Or is there a way to version schemas separately?
    • I have relations between the different schemas, and I've already found that the generated SQL doesn't always prefix the table name with the database name - I can live with making manual changes (or investigate with the SQLTranslator folks?), just want to know if i'm doing something wrong in preparing/installing and running migrations...
  • I think the above is the cause of my issues when dumping fixtures (using a single database in the --dsn flag)
    • I receive the error "DBIx::Class::Schema::source(): Can't find source for Addon1::Widget at (eval 260) line 17"
    • After some initial sleuthing, Schema::source() is looking for "Widget" instead of "Addon1::Widget"
    • Is this something I can solve with the right set of "extra_schema_loader_args"?

Thanks in advance!

jbakerdev avatar Aug 17 '20 15:08 jbakerdev