Skip to content

Commit

Permalink
feat: update alembic for list changes & type changes (pinterest#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
meowcodes authored Mar 25, 2021
1 parent b1e07f7 commit 15ea6f9
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion querybook/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from sqlalchemy import engine_from_config, pool
from logging.config import fileConfig
from env import QuerybookSettings
from models import Base

# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
Expand All @@ -19,7 +20,6 @@
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
from models import Base

target_metadata = Base.metadata

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""update board and board item descriptions
Revision ID: 1e3eb54fcb83
Revises: b8a9e3e18bcc
Create Date: 2021-03-23 21:00:35.909596
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql

# revision identifiers, used by Alembic.
revision = '1e3eb54fcb83'
down_revision = 'b8a9e3e18bcc'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('board_item',
sa.Column('description', sa.Text(length=16777215), nullable=True))
op.alter_column('board', 'description',
existing_type=sa.String(length=5000),
type_=sa.Text(length=16777215),
existing_nullable=True)
op.alter_column('query_metastore', 'acl_control',
existing_type=sa.Text(length=16777215),
type_=sa.JSON(),
existing_nullable=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('query_metastore', 'acl_control',
existing_type=sa.JSON(),
type_=sa.Text(length=16777215),
existing_nullable=False)
op.alter_column('board', 'description',
existing_type=sa.Text(length=16777215),
type_=sa.String(length=5000),
existing_nullable=True)
op.drop_column('board_item', 'description')
# ### end Alembic commands ###
9 changes: 3 additions & 6 deletions querybook/server/models/board.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
from sqlalchemy.orm import relationship, backref

from app import db
from const.db import (
name_length,
now,
description_length,
)
from const.db import name_length, now, mediumtext_length
from lib.sqlalchemy import CRUDMixin

Base = db.Base
Expand All @@ -22,7 +18,7 @@ class Board(CRUDMixin, Base):
deleted_at = sql.Column(sql.DateTime)

name = sql.Column(sql.String(length=name_length), nullable=False)
description = sql.Column(sql.String(length=description_length))
description = sql.Column(sql.Text(length=mediumtext_length))
public = sql.Column(sql.Boolean, default=True)
board_type = sql.Column(sql.String(length=name_length), default="")

Expand Down Expand Up @@ -87,6 +83,7 @@ class BoardItem(CRUDMixin, Base):
)
item_order = sql.Column(sql.Integer)
created_at = sql.Column(sql.DateTime, default=now)
description = sql.Column(sql.Text(length=mediumtext_length))

board = relationship(
"Board",
Expand Down
4 changes: 2 additions & 2 deletions querybook/server/models/metastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ class DataTableStatistics(Base, CRUDMixin):
table_id = sql.Column(
sql.Integer, sql.ForeignKey("data_table.id", ondelete="CASCADE"), nullable=False
)
key = sql.Column(sql.Text(length=utf8mb4_name_length), nullable=False, index=True)
key = sql.Column(sql.String(length=utf8mb4_name_length), nullable=False, index=True)
value = sql.Column(sql.JSON, nullable=False)
uid = sql.Column(sql.Integer, sql.ForeignKey("user.id",), nullable=True)

Expand All @@ -408,7 +408,7 @@ class DataTableColumnStatistics(Base, CRUDMixin):
sql.ForeignKey("data_table_column.id", ondelete="CASCADE"),
nullable=False,
)
key = sql.Column(sql.Text(length=utf8mb4_name_length), nullable=False, index=True)
key = sql.Column(sql.String(length=utf8mb4_name_length), nullable=False, index=True)
value = sql.Column(sql.JSON, nullable=False)
uid = sql.Column(sql.Integer, sql.ForeignKey("user.id",), nullable=True)

Expand Down

0 comments on commit 15ea6f9

Please sign in to comment.