From daa18d2098818028689450cd670053be4fc8fff2 Mon Sep 17 00:00:00 2001 From: rongzhang Date: Wed, 23 Oct 2024 21:05:56 +0000 Subject: [PATCH] alembic migration --- .../aa328ae9dced_add_github_datadoc_link.py | 56 +++++++++++++++++++ querybook/server/models/github.py | 2 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 querybook/migrations/versions/aa328ae9dced_add_github_datadoc_link.py diff --git a/querybook/migrations/versions/aa328ae9dced_add_github_datadoc_link.py b/querybook/migrations/versions/aa328ae9dced_add_github_datadoc_link.py new file mode 100644 index 000000000..522d9df9d --- /dev/null +++ b/querybook/migrations/versions/aa328ae9dced_add_github_datadoc_link.py @@ -0,0 +1,56 @@ +"""Add GitHub Datadoc Link + +Revision ID: aa328ae9dced +Revises: f7b11b3e3a95 +Create Date: 2024-10-23 21:04:55.052696 + +""" + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = "aa328ae9dced" +down_revision = "f7b11b3e3a95" +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table( + "github_link", + sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), + sa.Column("datadoc_id", sa.Integer(), nullable=False), + sa.Column("user_id", sa.Integer(), nullable=False), + sa.Column( + "directory", + sa.String(length=255), + nullable=False, + server_default="datadocs", + ), + sa.Column( + "created_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False + ), + sa.Column( + "updated_at", sa.DateTime(), server_default=sa.text("now()"), nullable=False + ), + sa.ForeignKeyConstraint( + ["datadoc_id"], + ["data_doc.id"], + ), + sa.ForeignKeyConstraint( + ["user_id"], + ["user.id"], + ), + sa.PrimaryKeyConstraint("id"), + sa.UniqueConstraint("datadoc_id"), + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_table("github_link") + # ### end Alembic commands ### diff --git a/querybook/server/models/github.py b/querybook/server/models/github.py index e802a656c..9405c3fcb 100644 --- a/querybook/server/models/github.py +++ b/querybook/server/models/github.py @@ -14,7 +14,7 @@ class GitHubLink(Base, CRUDMixin): sql.Integer, sql.ForeignKey("data_doc.id"), nullable=False, unique=True ) user_id = sql.Column(sql.Integer, sql.ForeignKey("user.id"), nullable=False) - directory = sql.Column(sql.String(255), nullable=False) + directory = sql.Column(sql.String(255), nullable=False, default="datadocs") created_at = sql.Column(sql.DateTime, server_default=func.now(), nullable=False) updated_at = sql.Column( sql.DateTime, server_default=func.now(), onupdate=func.now(), nullable=False