"""add news

Revision ID: 9c070b1a9f8b
Revises: <PASSWORD>
Create Date: 2021-03-07 19:01:38.609450

"""

# revision identifiers, used by Alembic.
revision = '9c070b1a9f8b'
down_revision = '<PASSWORD>'

from alembic import op
import sqlalchemy as sa


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('news',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.UnicodeText(), nullable=True),
    sa.Column('content', sa.UnicodeText(), nullable=True),
    sa.Column('sender_id', sa.Integer(), nullable=True),
    sa.Column('recipient_id', sa.Integer(), nullable=True),
    sa.Column('sample_id', sa.Integer(), nullable=True),
    sa.Column('published', sa.Date(), nullable=True),
    sa.Column('expires', sa.Date(), nullable=True),
    sa.ForeignKeyConstraint(['recipient_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['sample_id'], ['samples.id'], ),
    sa.ForeignKeyConstraint(['sender_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('linkusernews',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('news_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['news_id'], ['news.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.execute('''
        CREATE TABLE "actions_new" (
            id INTEGER NOT NULL, 
            timestamp DATE, 
            sample_id INTEGER, 
            description TEXT, 
            owner_id INTEGER,
            datecreated DATE,
            ordnum INTEGER, 
            news_id INTEGER,
            PRIMARY KEY (id), 
            CONSTRAINT actions FOREIGN KEY(owner_id) REFERENCES users (id), 
            FOREIGN KEY(sample_id) REFERENCES samples (id),
            FOREIGN KEY(news_id) REFERENCES news (id)
        );
    ''')
    op.execute('INSERT INTO actions_new (id, timestamp, sample_id, description, owner_id, datecreated, ordnum) SELECT id, timestamp, sample_id, description, owner_id, datecreated, ordnum FROM actions;')
    op.execute('DROP TABLE actions;')
    op.execute('ALTER TABLE actions_new RENAME TO actions;')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'actions', type_='foreignkey')
    op.drop_table('linkusernews')
    op.drop_table('news')
    # ### end Alembic commands ###

"""add news

Revision ID: 9c070b1a9f8b
Revises: <PASSWORD>
Create Date: 2021-03-07 19:01:38.609450

"""

# revision identifiers, used by Alembic.
revision = '9c070b1a9f8b'
down_revision = '<PASSWORD>'

from alembic import op
import sqlalchemy as sa


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('news',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.UnicodeText(), nullable=True),
    sa.Column('content', sa.UnicodeText(), nullable=True),
    sa.Column('sender_id', sa.Integer(), nullable=True),
    sa.Column('recipient_id', sa.Integer(), nullable=True),
    sa.Column('sample_id', sa.Integer(), nullable=True),
    sa.Column('published', sa.Date(), nullable=True),
    sa.Column('expires', sa.Date(), nullable=True),
    sa.ForeignKeyConstraint(['recipient_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['sample_id'], ['samples.id'], ),
    sa.ForeignKeyConstraint(['sender_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('linkusernews',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('news_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['news_id'], ['news.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.execute('''
        CREATE TABLE "actions_new" (
            id INTEGER NOT NULL, 
            timestamp DATE, 
            sample_id INTEGER, 
            description TEXT, 
            owner_id INTEGER,
            datecreated DATE,
            ordnum INTEGER, 
            news_id INTEGER,
            PRIMARY KEY (id), 
            CONSTRAINT actions FOREIGN KEY(owner_id) REFERENCES users (id), 
            FOREIGN KEY(sample_id) REFERENCES samples (id),
            FOREIGN KEY(news_id) REFERENCES news (id)
        );
    ''')
    op.execute('INSERT INTO actions_new (id, timestamp, sample_id, description, owner_id, datecreated, ordnum) SELECT id, timestamp, sample_id, description, owner_id, datecreated, ordnum FROM actions;')
    op.execute('DROP TABLE actions;')
    op.execute('ALTER TABLE actions_new RENAME TO actions;')
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'actions', type_='foreignkey')
    op.drop_table('linkusernews')
    op.drop_table('news')
    # ### end Alembic commands ###

add news  Revision ID: 9c070b1a9f8b Revises: <PASSWORD> Create Date: 2021-03-07 19:01:38.609450 # revision identifiers, used by Alembic. # ### commands auto generated by Alembic - please adjust! ### CREATE TABLE "actions_new" (             id INTEGER NOT NULL,              timestamp DATE,              sample_id INTEGER,              description TEXT,              owner_id INTEGER,             datecreated DATE,             ordnum INTEGER,              news_id INTEGER,             PRIMARY KEY (id),              CONSTRAINT actions FOREIGN KEY(owner_id) REFERENCES users (id),              FOREIGN KEY(sample_id) REFERENCES samples (id),             FOREIGN KEY(news_id) REFERENCES news (id)         ); # ### end Alembic commands ### # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ###