99 lines
		
	
	
	
		
			5.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			99 lines
		
	
	
	
		
			5.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| """Initial migration
 | |
| 
 | |
| Revision ID: 0e07095d2961
 | |
| Revises: 
 | |
| Create Date: 2025-08-29 01:28:57.822103
 | |
| 
 | |
| """
 | |
| from alembic import op
 | |
| import sqlalchemy as sa
 | |
| from sqlalchemy.dialects import postgresql
 | |
| 
 | |
| # revision identifiers, used by Alembic.
 | |
| revision = '0e07095d2961'
 | |
| down_revision = None
 | |
| branch_labels = None
 | |
| depends_on = None
 | |
| 
 | |
| 
 | |
| def upgrade():
 | |
|     # ### commands auto generated by Alembic - please adjust! ###
 | |
|     op.drop_table('admins')
 | |
|     with op.batch_alter_table('subscribers', schema=None) as batch_op:
 | |
|         batch_op.drop_index(batch_op.f('idx_subscribers_created_at'))
 | |
|         batch_op.drop_index(batch_op.f('idx_subscribers_email'))
 | |
|         batch_op.drop_index(batch_op.f('idx_subscribers_status'))
 | |
| 
 | |
|     op.drop_table('subscribers')
 | |
|     op.drop_table('admin_users')
 | |
|     op.drop_table('email_deliveries')
 | |
|     with op.batch_alter_table('newsletters', schema=None) as batch_op:
 | |
|         batch_op.drop_index(batch_op.f('idx_newsletters_sent_at'))
 | |
| 
 | |
|     op.drop_table('newsletters')
 | |
|     # ### end Alembic commands ###
 | |
| 
 | |
| 
 | |
| def downgrade():
 | |
|     # ### commands auto generated by Alembic - please adjust! ###
 | |
|     op.create_table('newsletters',
 | |
|     sa.Column('id', sa.INTEGER(), server_default=sa.text("nextval('newsletters_id_seq'::regclass)"), autoincrement=True, nullable=False),
 | |
|     sa.Column('subject', sa.TEXT(), autoincrement=False, nullable=False),
 | |
|     sa.Column('body', sa.TEXT(), autoincrement=False, nullable=False),
 | |
|     sa.Column('sent_at', postgresql.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
 | |
|     sa.Column('sent_by', sa.TEXT(), autoincrement=False, nullable=True),
 | |
|     sa.Column('recipient_count', sa.INTEGER(), server_default=sa.text('0'), autoincrement=False, nullable=True),
 | |
|     sa.Column('success_count', sa.INTEGER(), server_default=sa.text('0'), autoincrement=False, nullable=True),
 | |
|     sa.Column('failure_count', sa.INTEGER(), server_default=sa.text('0'), autoincrement=False, nullable=True),
 | |
|     sa.PrimaryKeyConstraint('id', name='newsletters_pkey'),
 | |
|     postgresql_ignore_search_path=False
 | |
|     )
 | |
|     with op.batch_alter_table('newsletters', schema=None) as batch_op:
 | |
|         batch_op.create_index(batch_op.f('idx_newsletters_sent_at'), [sa.literal_column('sent_at DESC')], unique=False)
 | |
| 
 | |
|     op.create_table('email_deliveries',
 | |
|     sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
 | |
|     sa.Column('newsletter_id', sa.INTEGER(), autoincrement=False, nullable=True),
 | |
|     sa.Column('email', sa.TEXT(), autoincrement=False, nullable=False),
 | |
|     sa.Column('status', sa.TEXT(), autoincrement=False, nullable=True),
 | |
|     sa.Column('sent_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
 | |
|     sa.Column('error_message', sa.TEXT(), autoincrement=False, nullable=True),
 | |
|     sa.CheckConstraint("status = ANY (ARRAY['sent'::text, 'failed'::text, 'bounced'::text])", name=op.f('email_deliveries_status_check')),
 | |
|     sa.ForeignKeyConstraint(['newsletter_id'], ['newsletters.id'], name=op.f('email_deliveries_newsletter_id_fkey')),
 | |
|     sa.PrimaryKeyConstraint('id', name=op.f('email_deliveries_pkey'))
 | |
|     )
 | |
|     op.create_table('admin_users',
 | |
|     sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
 | |
|     sa.Column('username', sa.TEXT(), autoincrement=False, nullable=False),
 | |
|     sa.Column('password', sa.TEXT(), autoincrement=False, nullable=False),
 | |
|     sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
 | |
|     sa.Column('last_login', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
 | |
|     sa.Column('is_active', sa.BOOLEAN(), server_default=sa.text('true'), autoincrement=False, nullable=True),
 | |
|     sa.PrimaryKeyConstraint('id', name=op.f('admin_users_pkey')),
 | |
|     sa.UniqueConstraint('username', name=op.f('admin_users_username_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
 | |
|     )
 | |
|     op.create_table('subscribers',
 | |
|     sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
 | |
|     sa.Column('email', sa.TEXT(), autoincrement=False, nullable=False),
 | |
|     sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
 | |
|     sa.Column('subscribed_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
 | |
|     sa.Column('status', sa.TEXT(), server_default=sa.text("'active'::text"), autoincrement=False, nullable=True),
 | |
|     sa.Column('source', sa.TEXT(), server_default=sa.text("'manual'::text"), autoincrement=False, nullable=True),
 | |
|     sa.CheckConstraint("status = ANY (ARRAY['active'::text, 'unsubscribed'::text])", name=op.f('subscribers_status_check')),
 | |
|     sa.PrimaryKeyConstraint('id', name=op.f('subscribers_pkey')),
 | |
|     sa.UniqueConstraint('email', name=op.f('subscribers_email_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
 | |
|     )
 | |
|     with op.batch_alter_table('subscribers', schema=None) as batch_op:
 | |
|         batch_op.create_index(batch_op.f('idx_subscribers_status'), ['status'], unique=False)
 | |
|         batch_op.create_index(batch_op.f('idx_subscribers_email'), ['email'], unique=False)
 | |
|         batch_op.create_index(batch_op.f('idx_subscribers_created_at'), [sa.literal_column('created_at DESC')], unique=False)
 | |
| 
 | |
|     op.create_table('admins',
 | |
|     sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
 | |
|     sa.Column('username', sa.VARCHAR(length=100), autoincrement=False, nullable=False),
 | |
|     sa.Column('password_hash', sa.VARCHAR(length=255), autoincrement=False, nullable=False),
 | |
|     sa.Column('created_at', postgresql.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'), autoincrement=False, nullable=True),
 | |
|     sa.PrimaryKeyConstraint('id', name=op.f('admins_pkey')),
 | |
|     sa.UniqueConstraint('username', name=op.f('admins_username_key'), postgresql_include=[], postgresql_nulls_not_distinct=False)
 | |
|     )
 | |
|     # ### end Alembic commands ###
 | 
