File size: 5,257 Bytes
46e055c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""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 ###