Files
notifications-api/migrations/versions/0242_template_folders.py
Leo Hemsted 936c8489b3 add TemplateFolder model
a TemplateFolder has a service, a name, and a parent. Parent is a
nullable foreign key pointing to another TemplateFolder instance. We
don't do any checks here for cyclical or otherwise invalid folder
structures so keep your data clean, folks!

Unsurprisingly, a Template can be part of a TemplateFolder - there's a
mapping class (template_folder_map to avoid giving it a dumb name) -
this mapping table shouldn't be interacted with directly - rather, you
should use the `Template.folder` or `TemplateFolder.templates`
relationship.
2018-10-26 17:50:31 +01:00

40 lines
1.4 KiB
Python

"""
Revision ID: 0242_template_folders
Revises: 0241_another_letter_org
Create Date: 2018-10-26 16:00:40.173840
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
revision = '0242_template_folders'
down_revision = '0241_another_letter_org'
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('template_folder',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('parent_id', postgresql.UUID(as_uuid=True), nullable=True),
sa.ForeignKeyConstraint(['parent_id'], ['template_folder.id'], ),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('template_folder_map',
sa.Column('template_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('template_folder_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.ForeignKeyConstraint(['template_folder_id'], ['template_folder.id'], ),
sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ),
sa.PrimaryKeyConstraint('template_id')
)
def downgrade():
op.drop_table('template_folder_map')
op.drop_table('template_folder')
# ### end Alembic commands ###