nupes-elections/alembic/versions/d7fed76a55bd_initial.py

266 lines
13 KiB
Python

"""initial
Revision ID: d7fed76a55bd
Revises:
Create Date: 2024-06-15 00:03:00.687812
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'd7fed76a55bd'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('bloc2024',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('nom', sa.String(length=32), nullable=False),
sa.Column('couleur', sa.String(length=7), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('nom')
)
op.create_table('nuance2024',
sa.Column('code', sa.String(length=8), nullable=False),
sa.Column('nom', sa.String(length=64), nullable=False),
sa.Column('couleur', sa.String(length=7), nullable=False),
sa.PrimaryKeyConstraint('code'),
sa.UniqueConstraint('nom')
)
op.create_table('region',
sa.Column('code_insee', sa.String(length=3), nullable=False),
sa.Column('libelle', sa.String(length=64), nullable=False),
sa.Column('geometry', sa.JSON(), nullable=False),
sa.PrimaryKeyConstraint('code_insee'),
sa.UniqueConstraint('libelle')
)
op.create_table('resultats2024_france',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('inscrits', sa.Integer(), nullable=False),
sa.Column('votants', sa.Integer(), nullable=False),
sa.Column('abstentions', sa.Integer(), nullable=False),
sa.Column('exprimes', sa.Integer(), nullable=False),
sa.Column('blancs', sa.Integer(), nullable=False),
sa.Column('nuls', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('departement',
sa.Column('code_insee', sa.String(length=3), nullable=False),
sa.Column('libelle', sa.String(length=64), nullable=False),
sa.Column('region_code', sa.String(length=3), nullable=False),
sa.Column('geometry', sa.JSON(), nullable=False),
sa.ForeignKeyConstraint(['region_code'], ['region.code_insee'], ),
sa.PrimaryKeyConstraint('code_insee'),
sa.UniqueConstraint('libelle')
)
op.create_table('liste2024',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('nom', sa.String(length=256), nullable=False),
sa.Column('nom_majuscules', sa.String(length=256), nullable=True),
sa.Column('numero', sa.Integer(), nullable=False),
sa.Column('nuance_id', sa.String(length=8), nullable=False),
sa.Column('bloc_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['bloc_id'], ['bloc2024.id'], ),
sa.ForeignKeyConstraint(['nuance_id'], ['nuance2024.code'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('nom'),
sa.UniqueConstraint('nom_majuscules'),
sa.UniqueConstraint('numero')
)
op.create_table('resultats2024_region',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('region_id', sa.String(length=3), nullable=False),
sa.Column('resultats_france_id', sa.Integer(), nullable=False),
sa.Column('inscrits', sa.Integer(), nullable=False),
sa.Column('votants', sa.Integer(), nullable=False),
sa.Column('abstentions', sa.Integer(), nullable=False),
sa.Column('exprimes', sa.Integer(), nullable=False),
sa.Column('blancs', sa.Integer(), nullable=False),
sa.Column('nuls', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['region_id'], ['region.code_insee'], ),
sa.ForeignKeyConstraint(['resultats_france_id'], ['resultats2024_france.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('candidat2024',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('liste_id', sa.Integer(), nullable=False),
sa.Column('ordre', sa.Integer(), nullable=False),
sa.Column('nom', sa.String(length=256), nullable=False),
sa.Column('prenom', sa.String(length=256), nullable=False),
sa.Column('sexe', sa.Enum('MASCULIN', 'FEMININ', name='genre'), nullable=False),
sa.Column('date_naissance', sa.Date(), nullable=False),
sa.Column('profession', sa.String(length=256), nullable=False),
sa.Column('code_personnalite', sa.Enum('DEFAUT', 'EURODEPUTE', 'DEPUTE', 'SENATEUR', 'MINISTRE', 'PRESIDENT_CONSEIL_REGIONAL', 'PRESIDENT_CONSEIL_DEPARTEMENTAL', 'MAIRE', name='personnalite'), nullable=False),
sa.Column('sortant', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['liste_id'], ['liste2024.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('circonscription',
sa.Column('id', sa.String(length=6), nullable=False),
sa.Column('departement_code', sa.String(length=3), nullable=False),
sa.Column('numero', sa.Integer(), nullable=False),
sa.Column('geometry', sa.JSON(), nullable=False),
sa.ForeignKeyConstraint(['departement_code'], ['departement.code_insee'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('commune',
sa.Column('code_insee', sa.String(length=5), nullable=False),
sa.Column('libelle', sa.String(length=64), nullable=False),
sa.Column('departement_code', sa.String(length=3), nullable=False),
sa.Column('geometry', sa.JSON(), nullable=False),
sa.ForeignKeyConstraint(['departement_code'], ['departement.code_insee'], ),
sa.PrimaryKeyConstraint('code_insee')
)
op.create_table('resultats2024_departement',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('dpt_id', sa.String(length=3), nullable=False),
sa.Column('resultats_region_id', sa.Integer(), nullable=True),
sa.Column('inscrits', sa.Integer(), nullable=False),
sa.Column('votants', sa.Integer(), nullable=False),
sa.Column('abstentions', sa.Integer(), nullable=False),
sa.Column('exprimes', sa.Integer(), nullable=False),
sa.Column('blancs', sa.Integer(), nullable=False),
sa.Column('nuls', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['dpt_id'], ['departement.code_insee'], ),
sa.ForeignKeyConstraint(['resultats_region_id'], ['resultats2024_region.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('voix2024_france',
sa.Column('liste_id', sa.Integer(), nullable=False),
sa.Column('resultats_france_id', sa.Integer(), nullable=False),
sa.Column('voix', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['liste_id'], ['liste2024.id'], ),
sa.ForeignKeyConstraint(['resultats_france_id'], ['resultats2024_france.id'], ),
sa.PrimaryKeyConstraint('liste_id', 'resultats_france_id')
)
op.create_table('voix2024_region',
sa.Column('liste_id', sa.Integer(), nullable=False),
sa.Column('resultats_region_id', sa.Integer(), nullable=False),
sa.Column('voix', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['liste_id'], ['liste2024.id'], ),
sa.ForeignKeyConstraint(['resultats_region_id'], ['resultats2024_region.id'], ),
sa.PrimaryKeyConstraint('liste_id', 'resultats_region_id')
)
op.create_table('bureau_vote',
sa.Column('id', sa.String(length=16), nullable=False),
sa.Column('commune_code', sa.String(length=5), nullable=False),
sa.Column('code_bureau', sa.String(length=8), nullable=False),
sa.Column('circo_code', sa.String(length=6), nullable=False),
sa.Column('libelle', sa.String(length=256), nullable=False),
sa.Column('adresse', sa.String(length=256), nullable=True),
sa.Column('geometry', sa.JSON(), nullable=False),
sa.ForeignKeyConstraint(['circo_code'], ['circonscription.id'], ),
sa.ForeignKeyConstraint(['commune_code'], ['commune.code_insee'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('resultats2024_circonscription',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('circo_id', sa.String(length=6), nullable=False),
sa.Column('resultats_departement_id', sa.Integer(), nullable=False),
sa.Column('inscrits', sa.Integer(), nullable=False),
sa.Column('votants', sa.Integer(), nullable=False),
sa.Column('abstentions', sa.Integer(), nullable=False),
sa.Column('exprimes', sa.Integer(), nullable=False),
sa.Column('blancs', sa.Integer(), nullable=False),
sa.Column('nuls', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['circo_id'], ['circonscription.id'], ),
sa.ForeignKeyConstraint(['resultats_departement_id'], ['resultats2024_departement.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('resultats2024_commune',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('commune_id', sa.String(length=5), nullable=False),
sa.Column('resultats_dpt_id', sa.Integer(), nullable=False),
sa.Column('inscrits', sa.Integer(), nullable=False),
sa.Column('votants', sa.Integer(), nullable=False),
sa.Column('abstentions', sa.Integer(), nullable=False),
sa.Column('exprimes', sa.Integer(), nullable=False),
sa.Column('blancs', sa.Integer(), nullable=False),
sa.Column('nuls', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['commune_id'], ['commune.code_insee'], ),
sa.ForeignKeyConstraint(['resultats_dpt_id'], ['resultats2024_departement.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('voix2024_departement',
sa.Column('liste_id', sa.Integer(), nullable=False),
sa.Column('resultats_departement_id', sa.Integer(), nullable=False),
sa.Column('voix', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['liste_id'], ['liste2024.id'], ),
sa.ForeignKeyConstraint(['resultats_departement_id'], ['resultats2024_departement.id'], ),
sa.PrimaryKeyConstraint('liste_id', 'resultats_departement_id')
)
op.create_table('resultats2024_bureau_vote',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('bv_id', sa.String(length=16), nullable=False),
sa.Column('resultats_commune_id', sa.Integer(), nullable=False),
sa.Column('resultats_circo_id', sa.Integer(), nullable=True),
sa.Column('inscrits', sa.Integer(), nullable=False),
sa.Column('votants', sa.Integer(), nullable=False),
sa.Column('abstentions', sa.Integer(), nullable=False),
sa.Column('exprimes', sa.Integer(), nullable=False),
sa.Column('blancs', sa.Integer(), nullable=False),
sa.Column('nuls', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['bv_id'], ['bureau_vote.id'], ),
sa.ForeignKeyConstraint(['resultats_circo_id'], ['resultats2024_circonscription.id'], ),
sa.ForeignKeyConstraint(['resultats_commune_id'], ['resultats2024_commune.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('voix2024_circonscription',
sa.Column('liste_id', sa.Integer(), nullable=False),
sa.Column('resultats_circonscription_id', sa.Integer(), nullable=False),
sa.Column('voix', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['liste_id'], ['liste2024.id'], ),
sa.ForeignKeyConstraint(['resultats_circonscription_id'], ['resultats2024_circonscription.id'], ),
sa.PrimaryKeyConstraint('liste_id', 'resultats_circonscription_id')
)
op.create_table('voix2024_commune',
sa.Column('liste_id', sa.Integer(), nullable=False),
sa.Column('resultats_commune_id', sa.Integer(), nullable=False),
sa.Column('voix', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['liste_id'], ['liste2024.id'], ),
sa.ForeignKeyConstraint(['resultats_commune_id'], ['resultats2024_commune.id'], ),
sa.PrimaryKeyConstraint('liste_id', 'resultats_commune_id')
)
op.create_table('voix2024_bureau_vote',
sa.Column('liste_id', sa.Integer(), nullable=False),
sa.Column('resultats_bureau_vote_id', sa.Integer(), nullable=False),
sa.Column('voix', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['liste_id'], ['liste2024.id'], ),
sa.ForeignKeyConstraint(['resultats_bureau_vote_id'], ['resultats2024_bureau_vote.id'], ),
sa.PrimaryKeyConstraint('liste_id', 'resultats_bureau_vote_id')
)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('voix2024_bureau_vote')
op.drop_table('voix2024_commune')
op.drop_table('voix2024_circonscription')
op.drop_table('resultats2024_bureau_vote')
op.drop_table('voix2024_departement')
op.drop_table('resultats2024_commune')
op.drop_table('resultats2024_circonscription')
op.drop_table('bureau_vote')
op.drop_table('voix2024_region')
op.drop_table('voix2024_france')
op.drop_table('resultats2024_departement')
op.drop_table('commune')
op.drop_table('circonscription')
op.drop_table('candidat2024')
op.drop_table('resultats2024_region')
op.drop_table('liste2024')
op.drop_table('departement')
op.drop_table('resultats2024_france')
op.drop_table('region')
op.drop_table('nuance2024')
op.drop_table('bloc2024')
# ### end Alembic commands ###