frioux / DBIx-Class-DeploymentHandler

https://metacpan.org/pod/DBIx::Class::DeploymentHandler
20 stars 25 forks source link

Nothing differentiates schemata in version table #34

Closed Altreus closed 7 years ago

Altreus commented 9 years ago

We build our applications out of Catalyst components, each of which may pull in a different model from a different DB package with its own DBIC schema in it.

As it stands, we can only use DeploymentHandler for one of them, because the version table doesn't have a way of specifying which Schema class the version number represents.

It would be great to be able to use DH for all of our schemata in the same database.

frioux commented 9 years ago

I'm not sure I understand; is your problem that the version table is underspecified so accidentally shared across DB's?

Altreus commented 9 years ago

Not quite; if you use a modular architecture, such that different Perl::Module::Schema classes can be written to the same physical database, only of them can be in the versions table.

So if I have

My::WebApp::Main::Schema::Result::*
My::Framework::Base::Schema::Result::*
My::Framework::Plugin::Schema::Result::*

I can use inheritance or Roles to ensure that My::WebApp::Main::Schema implements My::Framework::Base::Schema, and thus extends it, and use DeploymentHandler::VersionStorage::Standard::Component there to deploy WebApp::Main + Framework::Base.

But I can't have the Framework::Plugin schema independent of these. I'd have to compose them at the DBIC level, while so far we've been able to keep plugins almost completely separate from everything else. That's because the dbix_class_deploymenthandler_versions table can only hold one schema's versioning; either My::WebApp::Main::Schema or My::Framework::Plugin::Schema.

For Postgres, this is not so much of a problem, because Postgres has database > schema > table, but in my previous life with MySQL there's no schema in the middle to separate them. Also true of SQLite, which is probably going to be used reasonably often (by us, for example) to test things.

frioux commented 7 years ago

I think the solution to this is to create a different version table per schema. I documented how to set a diff version table here. Does this not solve the problem completely generically?

Altreus commented 7 years ago

That's very useful, and it does. Thanks!