feat: implement scoped dataset catalog and template input drafts

This commit is contained in:
yuxuanhui
2026-09-08 09:22:53 +08:00
parent 404a4d8a04
commit 01d169d118
30 changed files with 3024 additions and 37 deletions
@@ -0,0 +1,92 @@
"""scope catalog collections notes and input drafts"""
from alembic import op
import sqlalchemy as sa
revision = '0003'
down_revision = '0002'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('catalog_scopes',
sa.Column('key', sa.String(length=200), nullable=False),
sa.Column('scope', sa.JSON(), nullable=False),
sa.Column('catalog_version', sa.String(length=36), nullable=True),
sa.Column('synced_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('key')
)
op.create_table('catalog_batches',
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('scope_key', sa.String(length=200), nullable=False),
sa.Column('dataset_id', sa.String(length=200), nullable=True),
sa.Column('complete', sa.Boolean(), nullable=False),
sa.Column('count', sa.Integer(), nullable=False),
sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['id'], ['sync_jobs.id'], ),
sa.ForeignKeyConstraint(['scope_key'], ['catalog_scopes.key'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_catalog_batches_scope_key'), 'catalog_batches', ['scope_key'], unique=False)
op.create_table('catalog_notes',
sa.Column('scope_key', sa.String(length=200), nullable=False),
sa.Column('dataset_id', sa.String(length=200), nullable=False),
sa.Column('field_id', sa.String(length=200), nullable=False),
sa.Column('note', sa.Text(), nullable=False),
sa.Column('version', sa.Integer(), nullable=False),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['scope_key'], ['catalog_scopes.key'], ),
sa.PrimaryKeyConstraint('scope_key', 'dataset_id', 'field_id')
)
op.create_table('catalog_datasets',
sa.Column('scope_key', sa.String(length=200), nullable=False),
sa.Column('id', sa.String(length=200), nullable=False),
sa.Column('field_version', sa.String(length=36), nullable=True),
sa.ForeignKeyConstraint(['field_version'], ['catalog_batches.id'], ),
sa.ForeignKeyConstraint(['scope_key'], ['catalog_scopes.key'], ),
sa.PrimaryKeyConstraint('scope_key', 'id')
)
op.create_table('catalog_entries',
sa.Column('batch_id', sa.String(length=36), nullable=False),
sa.Column('id', sa.String(length=200), nullable=False),
sa.Column('name', sa.Text(), nullable=True),
sa.Column('category', sa.String(length=200), nullable=True),
sa.Column('subcategory', sa.String(length=200), nullable=True),
sa.Column('field_type', sa.String(length=100), nullable=True),
sa.Column('coverage', sa.Float(), nullable=True),
sa.Column('user_count', sa.Integer(), nullable=True),
sa.Column('alpha_count', sa.Integer(), nullable=True),
sa.Column('field_count', sa.Integer(), nullable=True),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('unit', sa.Text(), nullable=True),
sa.Column('synced_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['batch_id'], ['catalog_batches.id'], ),
sa.PrimaryKeyConstraint('batch_id', 'id')
)
op.create_table('template_inputs',
sa.Column('id', sa.String(length=36), nullable=False),
sa.Column('scope_key', sa.String(length=200), nullable=False),
sa.Column('dataset_id', sa.String(length=200), nullable=False),
sa.Column('collection_version', sa.String(length=36), nullable=False),
sa.Column('selection', sa.String(length=20), nullable=False),
sa.Column('field_ids', sa.JSON(), nullable=False),
sa.Column('field_types', sa.JSON(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=False),
sa.ForeignKeyConstraint(['collection_version'], ['catalog_batches.id'], ),
sa.ForeignKeyConstraint(['scope_key'], ['catalog_scopes.key'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_template_inputs_scope_key'), 'template_inputs', ['scope_key'], unique=False)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_template_inputs_scope_key'), table_name='template_inputs')
op.drop_table('template_inputs')
op.drop_table('catalog_entries')
op.drop_table('catalog_datasets')
op.drop_table('catalog_notes')
op.drop_index(op.f('ix_catalog_batches_scope_key'), table_name='catalog_batches')
op.drop_table('catalog_batches')
op.drop_table('catalog_scopes')
# ### end Alembic commands ###