Mariam-cours / migrations /versions /80f91a17b1db_initial_migration.py
kuro223's picture
jki
46e055c
raw
history blame
5.26 kB
"""Initial migration
Revision ID: 80f91a17b1db
Revises:
Create Date: 2025-02-17 12:20:44.860732
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '80f91a17b1db'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('sous_categorie',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('nom', sa.String(length=64), nullable=False),
sa.Column('matiere_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['matiere_id'], ['matiere.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('nom', 'matiere_id', name='_nom_matiere_uc')
)
op.create_table('texte',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('titre', sa.String(length=128), nullable=False),
sa.Column('contenu', sa.Text(), nullable=False),
sa.Column('sous_categorie_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['sous_categorie_id'], ['sous_categorie.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.drop_table('cours')
op.drop_table('subjects')
op.drop_table('texts')
op.drop_table('commentaire')
op.drop_table('categories')
op.drop_table('categorie')
with op.batch_alter_table('matiere', schema=None) as batch_op:
batch_op.alter_column('nom',
existing_type=sa.VARCHAR(length=255),
type_=sa.String(length=64),
existing_nullable=False)
batch_op.create_unique_constraint(None, ['nom'])
batch_op.drop_column('description')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('matiere', schema=None) as batch_op:
batch_op.add_column(sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True))
batch_op.drop_constraint(None, type_='unique')
batch_op.alter_column('nom',
existing_type=sa.String(length=64),
type_=sa.VARCHAR(length=255),
existing_nullable=False)
op.create_table('categorie',
sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('categorie_id_seq'::regclass)"), autoincrement=True, nullable=False),
sa.Column('nom', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('matiere_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['matiere_id'], ['matiere.id'], name='fk_matiere', ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id', name='categorie_pkey'),
postgresql_ignore_search_path=False
)
op.create_table('categories',
sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('categories_id_seq'::regclass)"), autoincrement=True, nullable=False),
sa.Column('name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
sa.Column('subject_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['subject_id'], ['subjects.id'], name='categories_subject_id_fkey'),
sa.PrimaryKeyConstraint('id', name='categories_pkey'),
postgresql_ignore_search_path=False
)
op.create_table('commentaire',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('contenu', sa.TEXT(), autoincrement=False, nullable=False),
sa.Column('auteur', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('date', postgresql.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
sa.Column('cours_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['cours_id'], ['cours.id'], name='fk_cours', ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id', name='commentaire_pkey')
)
op.create_table('texts',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('title', sa.VARCHAR(length=150), autoincrement=False, nullable=True),
sa.Column('content', sa.TEXT(), autoincrement=False, nullable=False),
sa.Column('category_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['category_id'], ['categories.id'], name='texts_category_id_fkey'),
sa.PrimaryKeyConstraint('id', name='texts_pkey')
)
op.create_table('subjects',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('name', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name='subjects_pkey')
)
op.create_table('cours',
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column('titre', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
sa.Column('description', sa.TEXT(), autoincrement=False, nullable=True),
sa.Column('categorie_id', sa.INTEGER(), autoincrement=False, nullable=False),
sa.ForeignKeyConstraint(['categorie_id'], ['categorie.id'], name='fk_categorie', ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id', name='cours_pkey')
)
op.drop_table('texte')
op.drop_table('sous_categorie')
# ### end Alembic commands ###