英文:
Alembic - how to create hypertable
问题
如何使用Alembic生成超级表?我想必须添加一些自定义调用,但应该添加在哪里?我尝试使用event.listen,但Alembic不会注册它。
英文:
How to generate hypertable using Alembic? Some custom call must be added I suppose, but where? I tried event.listen but Alembic does not register it.
答案1
得分: 1
你可以通过在Alembic中添加手动、自定义的迁移操作来创建超级表。
不能自动生成它,因为Alembic没有特定的支持,也不理解超级表。
英文:
You can create hypertables in Alembic by adding manual, custom, migration actions.
You cannot generate it automatically, because there is no specific support in Alembic for TimescaleDB and it does not understand hypertables.
答案2
得分: 0
以下是代码的翻译部分:
def upgrade() -> None:
op.create_table(
TABLE_NAME,
sa.Column('ts', sa.DateTime),
sa.Column('col1', sa.String(50)),
sa.Column('col2', sa.String(50)),
sa.Column('col3', sa.String(50)),
sa.Column('col4', sa.String(50)),
sa.Column('col5', sa.Integer),
sa.Column('col6', sa.Integer),
schema=SCHEMA,
if_not_exists=True,
)
op.execute(f"SELECT create_hypertable('{SCHEMA}.{TABLE_NAME}', 'ts');")
这是代码的翻译部分,不包括其他内容。
英文:
def upgrade() -> None:
op.create_table(
TABLE_NAME,
sa.Column('ts', sa.DateTime),
sa.Column('col1', sa.String(50)),
sa.Column('col2', sa.String(50)),
sa.Column('col3',sa.String(50)),
sa.Column('col4',sa.String(50)),
sa.Column('col5',sa.Integer),
sa.Column('col6',sa.Integer),
schema=SCHEMA,
if_not_exists=True,)
op.execute(f"SELECT create_hypertable('{SCHEMA}.{TABLE_NAME}', 'ts');")
This worked for me. Make sure you create the hypertable extension if needed or you'll get errors.:
CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论