On 04/21/2017 09:16 AM, Антонио Антуан wrote:
Helllo.
I have a model, with specified __tablename__ = 'base_table'.
In postgresql, the table has trigger, which executes before each insert:
it creates partition for current month (if it not exist yet), specifies
"INHERITS (base_table)" for new partition and insert data into it.
Is there any way to autodetect table inheritance and generate migration
script for it?
What's the actual migration you want to generate? E.g. start with A,
change to B....are you starting with Table(), and then adding
"postgresql_inherits" to it after the fact? it's not clear.
if you can illustrate what this migration would be I'd have some idea
what you are actually trying to do. The "trigger" you refer to seems
to be something that emits CREATE TABLE upon INSERT, which would be
outside the realm of Alembic.
If autodetection not working...
I can get list of inherited tables with such query:
|SELECT child.relname, parent.relname
FROM pg_catalog.pg_inherits
INNER JOIN pg_catalog.pg_class as child ON (pg_inherits.inhrelid =
child.oid)
INNER JOIN pg_catalog.pg_class as parent ON (pg_inherits.inhparent =
parent.oid)
WHERE inhparent = 'base_table'::regclass;|
Returned names can be specified as parameter "only" in "reflect()"
method of MetaData instance. Can I specify target table for each table
in metadata for migration?
I found just such solution:
|
for table_name in inherit_table_names:
meta_data.tables[table_name].name = "base_table"
I'm not really following what you're doing here. Changing the name of
a Table like that is probably not safe in general, depends on the context.
|
Is my solution safe?
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
You received this message because you are subscribed to the Google
Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to sqlalchemy+unsubscr...@googlegroups.com
<mailto:sqlalchemy+unsubscr...@googlegroups.com>.
To post to this group, send email to sqlalchemy@googlegroups.com
<mailto:sqlalchemy@googlegroups.com>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.