"""partition_apollo_followers Revision ID: 1f46b57f9a28 Revises: 94440b575488 Create Date: 2021-02-18 11:45:57.009334 """ # revision identifiers, used by Alembic. revision = '1f46b57f9a28' down_revision = '94440b575488' branch_labels = None depends_on = None from alembic import op import sqlalchemy as sa def upgrade(): op.execute(''' create table spy_apollo_followers_parts ( as_of date not null, artist_spyid varchar not null, followers_count integer not null ) partition by range(as_of); create table spy_apollo_followers_default partition of spy_apollo_followers_parts default; create unique index on spy_apollo_followers_default (as_of, artist_spyid); create table spy_apollo_followers_2011 partition of spy_apollo_followers_parts FOR VALUES FROM ('2020-11-01') TO ('2020-12-01'); create unique index on spy_apollo_followers_2011 (as_of, artist_spyid); create table spy_apollo_followers_2012 partition of spy_apollo_followers_parts FOR VALUES FROM ('2020-12-01') TO ('2021-01-01'); create unique index on spy_apollo_followers_2012 (as_of, artist_spyid); create table spy_apollo_followers_2101 partition of spy_apollo_followers_parts FOR VALUES FROM ('2021-01-01') TO ('2021-02-01'); create unique index on spy_apollo_followers_2101 (as_of, artist_spyid); create table spy_apollo_followers_2102 partition of spy_apollo_followers_parts FOR VALUES FROM ('2021-02-01') TO ('2021-03-01'); create unique index on spy_apollo_followers_2102 (as_of, artist_spyid); insert into spy_apollo_followers_parts (as_of, artist_spyid, followers_count) select as_of, artist_spyid, followers_count from spy_apollo_followers; alter table spy_apollo_followers rename to spy_apollo_followers_old; alter table spy_apollo_followers_parts rename to spy_apollo_followers; ''') def downgrade(): pass