"""create scheduled tasks

Revision ID: 8b97d5de5050
Revises: d1e116e8eea5
Create Date: 2023-03-21 15:42:19.412413+00:00

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8b97d5de5050'
down_revision = 'd1e116e8eea5'
branch_labels = None
depends_on = None


def upgrade():
	# ### commands auto generated by Alembic - please adjust! ###
	op.create_table('tasks_repeatable',
	sa.Column('id', sa.Integer(), nullable=False),
	sa.Column('author_id', sa.Integer(), nullable=False),
	sa.Column('type_id', sa.SmallInteger(), nullable=False),
	sa.Column('enabled', sa.Boolean(), nullable=False),
	sa.Column('run_state', sa.SmallInteger(), nullable=False),
	sa.Column('run_time_last', sa.DateTime(), nullable=True),
	sa.Column('frequency_day', sa.SmallInteger(), nullable=False),
	sa.Column('time_of_day_utc', sa.Time(), nullable=False),
	sa.Column('created_utc', sa.Integer(), nullable=False),
	sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
	sa.PrimaryKeyConstraint('id')
	)
	op.create_table('tasks_repeatable_python',
	sa.Column('id', sa.Integer(), nullable=False),
	sa.Column('import_path', sa.String(), nullable=False),
	sa.Column('callable', sa.String(), nullable=False),
	sa.ForeignKeyConstraint(['id'], ['tasks_repeatable.id'], ),
	sa.PrimaryKeyConstraint('id')
	)
	op.create_table('tasks_repeatable_runs',
	sa.Column('id', sa.Integer(), nullable=False),
	sa.Column('task_id', sa.Integer(), nullable=False),
	sa.Column('manual', sa.Boolean(), nullable=False),
	sa.Column('traceback_str', sa.Text(), nullable=True),
	sa.Column('completed_utc', sa.DateTime(), nullable=True),
	sa.Column('created_utc', sa.Integer(), nullable=False),
	sa.ForeignKeyConstraint(['task_id'], ['tasks_repeatable.id'], ),
	sa.PrimaryKeyConstraint('id')
	)
	op.create_table('tasks_repeatable_scheduled_submissions',
	sa.Column('id', sa.Integer(), nullable=False),
	sa.Column('author_id_submission', sa.Integer(), nullable=False),
	sa.Column('ghost', sa.Boolean(), nullable=False),
	sa.Column('private', sa.Boolean(), nullable=False),
	sa.Column('over_18', sa.Boolean(), nullable=False),
	sa.Column('is_bot', sa.Boolean(), nullable=False),
	sa.Column('title', sa.String(length=500), nullable=False),
	sa.Column('url', sa.String(), nullable=True),
	sa.Column('body', sa.Text(), nullable=True),
	sa.Column('body_html', sa.Text(), nullable=True),
	sa.Column('flair', sa.String(), nullable=True),
	sa.Column('embed_url', sa.String(), nullable=True),
	sa.ForeignKeyConstraint(['author_id_submission'], ['users.id'], ),
	sa.ForeignKeyConstraint(['id'], ['tasks_repeatable.id'], ),
	sa.PrimaryKeyConstraint('id')
	)
	op.add_column('submissions', sa.Column('task_id', sa.Integer(), nullable=True))
	op.create_foreign_key(None, 'submissions', 'tasks_repeatable_scheduled_submissions', ['task_id'], ['id'])
	# ### end Alembic commands ###


def downgrade():
	# ### commands auto generated by Alembic - please adjust! ###
	op.drop_constraint(None, 'submissions', type_='foreignkey')
	op.drop_column('submissions', 'task_id')
	op.drop_table('tasks_repeatable_scheduled_submissions')
	op.drop_table('tasks_repeatable_runs')
	op.drop_table('tasks_repeatable_python')
	op.drop_table('tasks_repeatable')
	# ### end Alembic commands ###
