Exemple #1
0
def upgrade():
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        op.add_column('message', sa.Column('draft', sa.Boolean()))
        op.add_column('comment', sa.Column('draft', sa.Boolean()))
        op.add_column('approval', sa.Column('draft', sa.Boolean()))

    conn = op.get_bind()
    conn.execute("update message set draft=pending")
    conn.execute("update comment set draft=pending")
    conn.execute("update approval set draft=pending")

    sqlite_alter_columns('message', [
        sa.Column('draft', sa.Boolean(), index=True, nullable=False),
        ])

    sqlite_alter_columns('comment', [
        sa.Column('draft', sa.Boolean(), index=True, nullable=False),
        ])

    sqlite_alter_columns('approval', [
        sa.Column('draft', sa.Boolean(), index=True, nullable=False),
        ])

    sqlite_drop_columns('comment', ['pending'])
    sqlite_drop_columns('approval', ['pending'])
def upgrade():
    sqlite_drop_columns('message', ['name'])
    sqlite_drop_columns('comment', ['name'])
    sqlite_drop_columns('approval', ['name'])
    sqlite_drop_columns('change', ['owner'])

    op.create_table(
        'account', sa.Column('key', sa.Integer(), nullable=False),
        sa.Column('id', sa.Integer(), index=True, unique=True, nullable=False),
        sa.Column('name', sa.String(length=255)),
        sa.Column('username', sa.String(length=255)),
        sa.Column('email', sa.String(length=255)),
        sa.PrimaryKeyConstraint('key'))

    op.create_index(op.f('ix_account_name'), 'account', ['name'], unique=True)
    op.create_index(op.f('ix_account_username'),
                    'account', ['name'],
                    unique=True)
    op.create_index(op.f('ix_account_email'), 'account', ['name'], unique=True)

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        op.add_column('message', sa.Column('account_key', sa.Integer()))
        op.add_column('comment', sa.Column('account_key', sa.Integer()))
        op.add_column('approval', sa.Column('account_key', sa.Integer()))
        op.add_column('change', sa.Column('account_key', sa.Integer()))
    sqlite_alter_columns(
        'message',
        [sa.Column('account_key', sa.Integer(), sa.ForeignKey('account.key'))])
    sqlite_alter_columns(
        'comment',
        [sa.Column('account_key', sa.Integer(), sa.ForeignKey('account.key'))])
    sqlite_alter_columns(
        'approval',
        [sa.Column('account_key', sa.Integer(), sa.ForeignKey('account.key'))])
    sqlite_alter_columns(
        'change',
        [sa.Column('account_key', sa.Integer(), sa.ForeignKey('account.key'))])

    op.create_index(op.f('ix_message_account_key'),
                    'message', ['account_key'],
                    unique=False)
    op.create_index(op.f('ix_comment_account_key'),
                    'comment', ['account_key'],
                    unique=False)
    op.create_index(op.f('ix_approval_account_key'),
                    'approval', ['account_key'],
                    unique=False)
    op.create_index(op.f('ix_change_account_key'),
                    'change', ['account_key'],
                    unique=False)

    connection = op.get_bind()
    project = sa.sql.table('project', sa.sql.column('updated', sa.DateTime))
    connection.execute(project.update().values({'updated': None}))

    approval = sa.sql.table('approval', sa.sql.column('pending'))
    connection.execute(approval.delete().where(approval.c.pending == False))
Exemple #3
0
def upgrade():
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        op.add_column('comment', sa.Column('file_key', sa.Integer()))
    sqlite_alter_columns(
        'comment',
        [sa.Column('file_key', sa.Integer(), sa.ForeignKey('file.key'))])

    update_query = sa.text(
        'update comment set file_key=:file_key where key=:key')
    file_query = sa.text(
        'select f.key from file f where f.revision_key=:revision_key and f.path=:path'
    )

    file_insert_query = sa.text(
        'insert into file (key, revision_key, path, old_path, status, inserted, deleted) '
        ' values (NULL, :revision_key, :path, NULL, NULL, NULL, NULL)')

    conn = op.get_bind()

    countres = conn.execute('select count(*) from comment')
    comments = countres.fetchone()[0]

    comment_res = conn.execute(
        'select p.name, c.number, c.status, r.key, r.number, m.file, m.key '
        'from project p, change c, revision r, comment m '
        'where m.revision_key=r.key and r.change_key=c.key and '
        'c.project_key=p.key order by p.name')

    count = 0
    for (pname, cnumber, cstatus, rkey, rnumber, mfile,
         mkey) in comment_res.fetchall():
        count += 1
        sys.stdout.write('Comment %s / %s\r' % (count, comments))
        sys.stdout.flush()

        file_res = conn.execute(file_query, revision_key=rkey, path=mfile)
        file_key = file_res.fetchone()
        if not file_key:
            conn.execute(file_insert_query, revision_key=rkey, path=mfile)
            file_res = conn.execute(file_query, revision_key=rkey, path=mfile)
            file_key = file_res.fetchone()
        fkey = file_key[0]
        file_res = conn.execute(update_query, file_key=fkey, key=mkey)
    sqlite_drop_columns('comment', ['revision_key', 'file'])
    print
def upgrade():
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        op.add_column('comment', sa.Column('file_key', sa.Integer()))
    sqlite_alter_columns('comment', [
            sa.Column('file_key', sa.Integer(), sa.ForeignKey('file.key'))
            ])

    update_query = sa.text('update comment set file_key=:file_key where key=:key')
    file_query = sa.text('select f.key from file f where f.revision_key=:revision_key and f.path=:path')

    file_insert_query = sa.text('insert into file (key, revision_key, path, old_path, status, inserted, deleted) '
                                ' values (NULL, :revision_key, :path, NULL, NULL, NULL, NULL)')

    conn = op.get_bind()

    countres = conn.execute('select count(*) from comment')
    comments = countres.fetchone()[0]

    comment_res = conn.execute('select p.name, c.number, c.status, r.key, r.number, m.file, m.key '
                               'from project p, change c, revision r, comment m '
                               'where m.revision_key=r.key and r.change_key=c.key and '
                               'c.project_key=p.key order by p.name')

    count = 0
    for (pname, cnumber, cstatus, rkey, rnumber, mfile, mkey) in comment_res.fetchall():
        count += 1
        sys.stdout.write('Comment %s / %s\r' % (count, comments))
        sys.stdout.flush()

        file_res = conn.execute(file_query, revision_key=rkey, path=mfile)
        file_key = file_res.fetchone()
        if not file_key:
            conn.execute(file_insert_query, revision_key=rkey, path=mfile)
            file_res = conn.execute(file_query, revision_key=rkey, path=mfile)
            file_key = file_res.fetchone()
        fkey = file_key[0]
        file_res = conn.execute(update_query, file_key=fkey, key=mkey)
    sqlite_drop_columns('comment', ['revision_key', 'file'])
    print
def upgrade():
    sqlite_drop_columns("message", ["name"])
    sqlite_drop_columns("comment", ["name"])
    sqlite_drop_columns("approval", ["name"])
    sqlite_drop_columns("change", ["owner"])

    op.create_table(
        "account",
        sa.Column("key", sa.Integer(), nullable=False),
        sa.Column("id", sa.Integer(), index=True, unique=True, nullable=False),
        sa.Column("name", sa.String(length=255)),
        sa.Column("username", sa.String(length=255)),
        sa.Column("email", sa.String(length=255)),
        sa.PrimaryKeyConstraint("key"),
    )

    op.create_index(op.f("ix_account_name"), "account", ["name"], unique=True)
    op.create_index(op.f("ix_account_username"), "account", ["name"], unique=True)
    op.create_index(op.f("ix_account_email"), "account", ["name"], unique=True)

    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        op.add_column("message", sa.Column("account_key", sa.Integer()))
        op.add_column("comment", sa.Column("account_key", sa.Integer()))
        op.add_column("approval", sa.Column("account_key", sa.Integer()))
        op.add_column("change", sa.Column("account_key", sa.Integer()))
    sqlite_alter_columns("message", [sa.Column("account_key", sa.Integer(), sa.ForeignKey("account.key"))])
    sqlite_alter_columns("comment", [sa.Column("account_key", sa.Integer(), sa.ForeignKey("account.key"))])
    sqlite_alter_columns("approval", [sa.Column("account_key", sa.Integer(), sa.ForeignKey("account.key"))])
    sqlite_alter_columns("change", [sa.Column("account_key", sa.Integer(), sa.ForeignKey("account.key"))])

    op.create_index(op.f("ix_message_account_key"), "message", ["account_key"], unique=False)
    op.create_index(op.f("ix_comment_account_key"), "comment", ["account_key"], unique=False)
    op.create_index(op.f("ix_approval_account_key"), "approval", ["account_key"], unique=False)
    op.create_index(op.f("ix_change_account_key"), "change", ["account_key"], unique=False)

    connection = op.get_bind()
    project = sa.sql.table("project", sa.sql.column("updated", sa.DateTime))
    connection.execute(project.update().values({"updated": None}))

    approval = sa.sql.table("approval", sa.sql.column("pending"))
    connection.execute(approval.delete().where(approval.c.pending == False))