fix: make hypertable creation conditional on TimescaleDB extension
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
The alembic migration unconditionally called create_hypertable() which fails if TimescaleDB isn't installed on the PostgreSQL instance. Wrap in a DO block that checks for the extension first.
This commit is contained in:
parent
efc91e9ad0
commit
e73d62cd3a
1 changed files with 11 additions and 5 deletions
|
|
@ -254,11 +254,17 @@ def upgrade() -> None:
|
||||||
sa.Column("sharpe_ratio", sa.Float, nullable=True),
|
sa.Column("sharpe_ratio", sa.Float, nullable=True),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Convert timeseries tables to TimescaleDB hypertables.
|
# Convert timeseries tables to TimescaleDB hypertables if the extension is available.
|
||||||
# These calls are idempotent-safe when the extension is loaded.
|
op.execute("""
|
||||||
op.execute("SELECT create_hypertable('market_data', 'timestamp', if_not_exists => TRUE)")
|
DO $$
|
||||||
op.execute("SELECT create_hypertable('portfolio_snapshots', 'timestamp', if_not_exists => TRUE)")
|
BEGIN
|
||||||
op.execute("SELECT create_hypertable('strategy_metrics', 'timestamp', if_not_exists => TRUE)")
|
IF EXISTS (SELECT 1 FROM pg_extension WHERE extname = 'timescaledb') THEN
|
||||||
|
PERFORM create_hypertable('market_data', 'timestamp', if_not_exists => TRUE);
|
||||||
|
PERFORM create_hypertable('portfolio_snapshots', 'timestamp', if_not_exists => TRUE);
|
||||||
|
PERFORM create_hypertable('strategy_metrics', 'timestamp', if_not_exists => TRUE);
|
||||||
|
END IF;
|
||||||
|
END $$;
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue