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

Should we create a Schema class? #7

Closed
FCO opened this issue Aug 18, 2018 · 12 comments
Closed

Should we create a Schema class? #7

FCO opened this issue Aug 18, 2018 · 12 comments
Labels
hacktoberfest help wanted Extra attention is needed question Further information is requested

Comments

@FCO
Copy link
Owner

FCO commented Aug 18, 2018

No description provided.

@FCO
Copy link
Owner Author

FCO commented Oct 2, 2018

How to create different models on different files? Because the way relationship works its verry probably that a model reffer another model and vice-versa

@FCO FCO added help wanted Extra attention is needed question Further information is requested hacktoberfest labels Oct 2, 2018
@FCO
Copy link
Owner Author

FCO commented Dec 27, 2018

Its not needed any more, once you can create relationship that will be lazily evaluated.

@FCO FCO closed this as completed Dec 27, 2018
@Xliff
Copy link
Contributor

Xliff commented Mar 15, 2019

I agree with the idea of creating a class that is a collection of models. How about we use 'Collection' as the name instead of 'Schema'? Especially since we may need to use that term somewhere else in the code.

Collections would work like this:

Collections and models in one file:

Collection AB {
  model B is table<bbb> { ... }
  model A is table<aaa> { has UInt $.id is serial; has B @.bs is relationship{ .a-id } }
  model B { has UInt $.id is serial; has UInt $.a-id is referencing{ A.id }; has A $.a is relationship{ .a-id } }
 
  has A $.a;
  has B $.b;
}

Or in multiple files:

use Model1;
use Model2;
use Model3;
 
Collection AB {
  has Model1 $.model1;
  has Model2 $.model2;
  has Model3 $.model3;
}

And objects can be versioned, ala:

use Model1:ver<0.1>;
use Model2:ver<1.3>;
use Model3:ver<1.0>;
 
Collection AB:ver<1.0> {
  has Model1 $.model1;
  has Model2 $.model2;
  has Model3 $.model3;
}

@FCO FCO reopened this Mar 15, 2019
@Xliff
Copy link
Contributor

Xliff commented Mar 15, 2019

The issue of getting two versions of the same Model or Collection to interoperate (migrations perhaps) is a critical issue that should be discussed if this is to be carried further.

@FCO FCO mentioned this issue Mar 15, 2019
@FCO
Copy link
Owner Author

FCO commented Mar 15, 2019

what about collection instead of Collection?

@Xliff
Copy link
Contributor

Xliff commented Mar 15, 2019

Fine with me, but why the change in case?

@FCO
Copy link
Owner Author

FCO commented Mar 15, 2019

model is lowercase, class is lowercase... I just think collection in lowercase would be consistent...

@Altreus
Copy link
Contributor

Altreus commented May 31, 2019

I like the way @Xliff is thinking. Whether we say collection or schema is of no odds to me, but I think I would find it clearer if it were schema. I don't see any reason why a model couldn't exist in more than one schema, after all.

In fact, I really like the idea of having a schema that is simply a subset of all the models you have in your app. That way, different parts of the app can be given different scopes.

We could go as far as to say, if you are related to a model not in your schema, you can't use it (rather than trying to look for it).

@Altreus
Copy link
Contributor

Altreus commented May 31, 2019

I don't know that having different versions of the same model at the same time even makes sense. Taking a cue from DBIx::Class in Perl 5 land, the entire schema has a single version, since the status of all tables in the database determines whether or not they will work together.

The model classes that we create relate directly to a real-world table in a database somewhere. Only the matching versions of the models themselves are guaranteed to work with the corresponding table in the database. If we update a model and deploy the new table structure to an existing database, the old version of the model cannot (in the general case) work with this new table structure.

Ultimately, I don't think it makes any sense to support different versions of the same model in the same schema (or collection or whatever).

However, you could easily create a schema that contains an old version of the model and works on an old version of the database.

I propose the database handle be part of the instantiated schema object.

use MyApp::Schema::Model1;
use MyApp::Schema::Model2;
use MyApp::Schema::Model3;

use Red;

schema MyApp::Schema {
  has Model1 $model1;
  has Model2 $model2;
  has Model3 $model3;
}

my $*RED-SCHEMA = MyApp::Schema.new: database => database "SQLite";

And then elsewhere, you can create a schema that is compatible with an outdated database:

use MyApp::Schema::Model1:ver<0.1>;
use MyApp::Schema::Model2;
use MyApp::Schema::Model3;

use Red;

schema MyApp::Schema {
  has Model1 $model1;
  has Model2 $model2;
  has Model3 $model3;
}

# Probably export this or something
my $compatibility-schema = MyApp::Schema.new:
   database => database( "SQLite", :database<outdated.db> );

@FCO
Copy link
Owner Author

FCO commented May 31, 2019

The idea of using different versions would be to support migrations (#15)

@FCO
Copy link
Owner Author

FCO commented Jul 24, 2019

Maybe schema should be a CompUnit::Repository?

@jonathanstowe
Copy link
Contributor

Yeah it wouldn't be dissimilar to a plugin loader with some additional metadata.

@FCO FCO closed this as completed Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants