예제 #1
0
def upgrade():
    op.create_table(
        "group_stats",
        sa.Column("group_id", sa.Integer(), nullable=False),
        sa.Column(
            "stat",
            postgresql.ENUM("TOPICS_POSTED", "COMMENTS_POSTED", name="groupstattype"),
            nullable=False,
        ),
        sa.Column("period", postgresql.TSTZRANGE(), nullable=False),
        sa.Column("value", sa.Float(), nullable=False),
        sa.ForeignKeyConstraint(
            ["group_id"],
            ["groups.group_id"],
            name=op.f("fk_group_stats_group_id_groups"),
        ),
        sa.PrimaryKeyConstraint(
            "group_id", "stat", "period", name=op.f("pk_group_stats")
        ),
    )
    op.create_index(
        "ix_group_stats_period_gist",
        "group_stats",
        ["period"],
        unique=False,
        postgresql_using="gist",
    )
예제 #2
0
def datetime_range(
        lower=datetime.now(tz=timezone.utc), upper=None, nullable=False):
    """Postgres DateTime Range column mapping.
    """
    return sa.Column(postgresql.TSTZRANGE(),
                     default=pg_extras.DateTimeTZRange(lower, upper),
                     nullable=nullable)
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'pgrastertime', sa.Column('id', sa.BigInteger(), nullable=False),
        sa.Column('tile_id', sa.BigInteger(), nullable=False),
        sa.Column('raster', geoalchemy2.types.Raster(), nullable=False),
        sa.Column('resolution', sa.Float(), nullable=False),
        sa.Column('filename', sa.UnicodeText(), nullable=True),
        sa.Column('sys_period', postgresql.TSTZRANGE(), nullable=False),
        sa.PrimaryKeyConstraint('id'))
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('session', sa.Column('timespan', postgresql.TSTZRANGE(), nullable=True))
    op.create_index('ix_session_timespan', 'session', ['timespan'], unique=False, postgresql_using='gist')
    op.add_column('test', sa.Column('timespan', postgresql.TSTZRANGE(), nullable=True))
    op.create_index('ix_test_timespan', 'test', ['timespan'], unique=False, postgresql_using='gist')

    # sessions
    op.execute(f'''
    insert into background_migration(name, remaining_num_items_query, update_query)
    values (
    '{_NAME_TEMPLATE.format("session")}',
    'select count(*) from "session" where timespan IS NULL',
    'update "session" set timespan = tstzrange(to_timestamp(start_time), to_timestamp(CASE WHEN end_time IS NULL THEN next_keepalive ELSE end_time END), ''[]'') where id in (select id from "session" where timespan is NULL limit \\:batch_size)'
    )''')


    update_query = f'''
    UPDATE test
    SET timespan = TSTZRANGE(
        TO_TIMESTAMP(test.start_time),
        CASE WHEN test.end_time IS NOT NULL THEN
           TO_TIMESTAMP(test.end_time)
        ELSE GREATEST(
            UPPER("session".timespan),
            TO_TIMESTAMP(test.start_time))
        END, ''[]'')
    FROM "session"
    WHERE "session".id = test.session_id AND test.id IN (
      SELECT id FROM "test" WHERE timespan IS NULL LIMIT \\:batch_size
    )
    '''.strip()

    # tests
    op.execute(f'''
    insert into background_migration(name, remaining_num_items_query, update_query)
    values (
    '{_NAME_TEMPLATE.format("test")}',
    'select count(*) from "test" where timespan IS NULL',
    '{update_query}'
    )''')
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('events',
                  sa.Column('month_number', sa.SmallInteger(), nullable=False))
    op.add_column(
        'events',
        sa.Column('scheduled_tz_duration',
                  postgresql.TSTZRANGE(),
                  nullable=False))
    op.add_column(
        'events',
        sa.Column('scheduling_tz_duration',
                  postgresql.TSTZRANGE(),
                  nullable=False))
    op.add_column(
        'events',
        sa.Column('utc_duration', postgresql.TSTZRANGE(), nullable=False))
    op.drop_column('events', 'scheduling_tz_end')
    op.drop_column('events', 'scheduled_tz_end')
    op.drop_column('events', 'scheduling_tz_start')
    op.drop_column('events', 'utc_start')
    op.drop_column('events', 'scheduled_tz_start')
    op.drop_column('events', 'utc_end')
    op.add_column(
        'schedules',
        sa.Column('local_duration', postgresql.TSTZRANGE(), nullable=False))
    op.add_column('schedules',
                  sa.Column('month_number', sa.SmallInteger(), nullable=False))
    op.add_column(
        'schedules',
        sa.Column('utc_duration', postgresql.TSRANGE(), nullable=False))
    op.drop_column('schedules', 'utc_open')
    op.drop_column('schedules', 'local_tz_open')
    op.drop_column('schedules', 'local_tz_end')
    op.drop_column('schedules', 'utc_end')
    op.add_column(
        'users', sa.Column('reset_token', sa.String(length=36), nullable=True))
    op.create_index(op.f('ix_users_reset_token'),
                    'users', ['reset_token'],
                    unique=True)