-
Notifications
You must be signed in to change notification settings - Fork 93
Description
Currently, the schema objects declares the database at declaration time and then each table is declared by the schema decorator.
For some scenarios requiring better modularity---in DataJoint Elements in particular---it becomes necessary to define and execute the module without defining the schema and then define them all at once in some importing module. Then the same module can be used to create multiple databases.
To support this functionality, I propose to allow the schema object to defer the declaration of the schema and the tables.
Omitted the database name will create a deferred schema.
schema = dj.Schema()This schema object can then be used to declare the database schema and to switch between database schemas using the switch method.
schema.activate('database_name')This has the effect of switching the database and declaring the new tables.
One can call schema.switch again to switch to another database. All the decorated classes will now start querying that database.
The declaration will use the context of the original schema object, so declare has the option to add new object to its the context.
schema.activate('database_name', add_objects={'Subject': Animal, 'Session': Session})