Comments (4)
is there a way I can have each module register their own entities?
you'll want to keep the call to register_entities in env.py
because
- it should only be called once
- due to python's import system, if you accidentally didn't import the location where
register_entities
was called, none of those entities would be visible to alembic
Or should each module expose a list of entities, and then I need to import those in my env.py?
that would work. it doesn't have any opinion about how you would want to expose the entities to env.py
Perhaps it would be possible to add a similar mechanism that registers an entity on each subclass instantiation, e.g. using the init_subclass mechanism
that would be an option, but requiring a user to collect all entities in env.py explicitly & deciding which ones to add in register_entities
, was an intentional design decision. It allows user's to put arbitrary rules in env.py for configuration (e.g. changing the schema name dynamically). Its also the least confusing for newcomers.
If your project has no import side-effects, there is helper function available that will traverse your package and collect all instances of an arbitrary class into a list.
# env.py
from alembic_utils.experimental import collect_instance
from alembic_utils.pg_view import PGView
from alembic_utils.replaceable_entity import register_entities
import myapp
instances: List[PGView] = collect_instances(myapp, PGView)
register_entities(*instances)
that's your best bet if you want to avoid plumbing lots of imports
from alembic_utils.
from alembic_utils.
Would it be possible to keep track of the instantiated functions/views inside PGView/PGFunction constructors? Something like
_pg_functions = []
class PGFunction:
def __init__(self, *args, **kwargs):
...
_pg_functions.append(self)
Then I guess at the point of the migration generation register_entities(*_pg_functions, *_pg_views)
could be called behind the scenes? Of course, this can also be done on the user side, by extending the PGFunction
and PGView
classes.
EDIT: If there is an auto_register()
function that just calls register_entities(*_pg_functions, *_pg_views)
and has to be called explicitly by the user inside env.py
, then the users could still omit the call and apply their arbitrary rules for registration.
from alembic_utils.
My concerns with any automatic registration approach are:
- they fail unless the
ReplaceableEntity
is on an import path inenv.py
- less configurable / explicit
So long as you don't have import side effects, the snippet using collect_instances
above should be enough to get the behavior you're looking for
from alembic_utils.
Related Issues (20)
- [Question] Using Alembic Utils without SQL Alchemy models HOT 3
- [QUESTION] compatibility with sqlalchemy_utils.functions.create_database HOT 2
- Compatibility with SQLAlchemy 2.0 HOT 4
- How to add a function with an " text[] default array['text', 'text2']"? HOT 1
- PGExtension replace `create` with `create if not exists` HOT 4
- Must be owner of materialized view mat_view_name HOT 2
- Alembic autogenerate broken for 'internal' PG functions HOT 5
- INFO: Transaction approach incompatible with MySQL
- alembic check broken - diff cannot be rendered HOT 1
- Materialized view change detection fails if upstream view has changed HOT 6
- DropOp dependency ordering when dropping multiple associated entities HOT 4
- Publishing next release HOT 1
- alembic_utils does not work with Redshift Dialect. HOT 1
- Adapting simulate_entities() to use .begin() instead of .begin_nested() HOT 1
- Extremely slow HOT 3
- gracefully handle when a migrator needs to modify a column that a view depends on HOT 8
- Creating an ORM Table mapping on a view will generate a migration to create a table HOT 4
- [Question] How to add a unique index to definition for PGMaterializedView HOT 4
- Colon character escaped unnecessarily in view autogeneration HOT 4
- Downgrade does not reflect old definition
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from alembic_utils.