Initial commit: InviteMe production redesign

This commit is contained in:
InviteMe Developer
2026-09-01 10:52:35 +03:00
commit 0d0868d998
71 changed files with 6912 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
Single-database configuration for Flask.
+50
View File
@@ -0,0 +1,50 @@
# A generic, single database configuration.
[alembic]
# template used to generate migration files
# file_template = %%(rev)s_%%(slug)s
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic,flask_migrate
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
qualname =
[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = INFO
handlers =
qualname = alembic
[logger_flask_migrate]
level = INFO
handlers =
qualname = flask_migrate
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S
+113
View File
@@ -0,0 +1,113 @@
import logging
from logging.config import fileConfig
from flask import current_app
from alembic import context
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
fileConfig(config.config_file_name)
logger = logging.getLogger('alembic.env')
def get_engine():
try:
# this works with Flask-SQLAlchemy<3 and Alchemical
return current_app.extensions['migrate'].db.get_engine()
except (TypeError, AttributeError):
# this works with Flask-SQLAlchemy>=3
return current_app.extensions['migrate'].db.engine
def get_engine_url():
try:
return get_engine().url.render_as_string(hide_password=False).replace(
'%', '%%')
except AttributeError:
return str(get_engine().url).replace('%', '%%')
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
config.set_main_option('sqlalchemy.url', get_engine_url())
target_db = current_app.extensions['migrate'].db
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def get_metadata():
if hasattr(target_db, 'metadatas'):
return target_db.metadatas[None]
return target_db.metadata
def run_migrations_offline():
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url, target_metadata=get_metadata(), literal_binds=True
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online():
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
# this callback is used to prevent an auto-migration from being generated
# when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0]
if script.upgrade_ops.is_empty():
directives[:] = []
logger.info('No changes in schema detected.')
conf_args = current_app.extensions['migrate'].configure_args
if conf_args.get("process_revision_directives") is None:
conf_args["process_revision_directives"] = process_revision_directives
connectable = get_engine()
with connectable.connect() as connection:
context.configure(
connection=connection,
target_metadata=get_metadata(),
**conf_args
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()
+24
View File
@@ -0,0 +1,24 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade():
${upgrades if upgrades else "pass"}
def downgrade():
${downgrades if downgrades else "pass"}
@@ -0,0 +1,139 @@
"""Initial production schema
Revision ID: 5e84226bd650
Revises:
Create Date: 2026-08-31 10:22:33.543712
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '5e84226bd650'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('smtp_settings',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('mail_server', sa.String(length=255), nullable=False),
sa.Column('mail_port', sa.Integer(), nullable=False),
sa.Column('mail_use_ssl', sa.Boolean(), nullable=False),
sa.Column('mail_username', sa.String(length=255), nullable=False),
sa.Column('mail_password', sa.String(length=1024), nullable=False),
sa.Column('mail_default_sender', sa.String(length=255), nullable=True),
sa.Column('use_local_outlook', sa.Boolean(), nullable=False),
sa.Column('use_ews', sa.Boolean(), nullable=False),
sa.Column('ews_url', sa.String(length=500), nullable=True),
sa.Column('imap_server', sa.String(length=255), nullable=True),
sa.Column('imap_port', sa.Integer(), nullable=False),
sa.Column('imap_use_ssl', sa.Boolean(), nullable=False),
sa.Column('imap_username', sa.String(length=255), nullable=True),
sa.Column('imap_password', sa.String(length=1024), nullable=True),
sa.Column('imap_folder', sa.String(length=255), nullable=True),
sa.Column('imap_save_copy', sa.Boolean(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(length=100), nullable=False),
sa.Column('password_hash', sa.String(length=255), nullable=False),
sa.Column('role', sa.String(length=20), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('session_version', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('username')
)
op.create_table('audit_logs',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('username', sa.String(length=100), nullable=True),
sa.Column('action', sa.String(length=50), nullable=False),
sa.Column('target_type', sa.String(length=50), nullable=True),
sa.Column('target_id', sa.String(length=50), nullable=True),
sa.Column('details', sa.Text(), nullable=True),
sa.Column('ip_address', sa.String(length=45), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('events',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('event_date', sa.DateTime(), nullable=True),
sa.Column('location', sa.String(length=255), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('created_by_id', sa.Integer(), nullable=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('ticket_title', sa.String(length=255), nullable=True),
sa.Column('ticket_subtitle', sa.String(length=255), nullable=True),
sa.Column('ticket_body_text', sa.Text(), nullable=True),
sa.Column('ticket_background_color', sa.String(length=7), nullable=True),
sa.Column('ticket_text_color', sa.String(length=7), nullable=True),
sa.Column('ticket_accent_color', sa.String(length=7), nullable=True),
sa.Column('ticket_show_qr', sa.Boolean(), nullable=False),
sa.Column('ticket_show_photo', sa.Boolean(), nullable=False),
sa.Column('ticket_layout', sa.String(length=20), nullable=True),
sa.Column('logo_filename', sa.String(length=255), nullable=True),
sa.ForeignKeyConstraint(['created_by_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('event_staff',
sa.Column('event_id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['event_id'], ['events.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('event_id', 'user_id')
)
op.create_table('guests',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('event_id', sa.Integer(), nullable=False),
sa.Column('department', sa.String(length=255), nullable=False),
sa.Column('last_name', sa.String(length=255), nullable=True),
sa.Column('first_name', sa.String(length=255), nullable=True),
sa.Column('middle_name', sa.String(length=255), nullable=True),
sa.Column('full_name', sa.String(length=255), nullable=False),
sa.Column('position', sa.String(length=255), nullable=True),
sa.Column('email', sa.String(length=255), nullable=False),
sa.Column('phone', sa.String(length=50), nullable=True),
sa.Column('photo_filename', sa.String(length=255), nullable=True),
sa.Column('token', sa.String(length=36), nullable=False),
sa.Column('qr_filename', sa.String(length=255), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('invitation_sent', sa.Boolean(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.Column('updated_at', sa.DateTime(), nullable=False),
sa.ForeignKeyConstraint(['event_id'], ['events.id'], ),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('token')
)
op.create_table('check_ins',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('guest_id', sa.Integer(), nullable=False),
sa.Column('event_id', sa.Integer(), nullable=True),
sa.Column('checked_in_at', sa.DateTime(), nullable=False),
sa.Column('device_info', sa.String(length=500), nullable=True),
sa.ForeignKeyConstraint(['event_id'], ['events.id'], ),
sa.ForeignKeyConstraint(['guest_id'], ['guests.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('check_ins')
op.drop_table('guests')
op.drop_table('event_staff')
op.drop_table('events')
op.drop_table('audit_logs')
op.drop_table('users')
op.drop_table('smtp_settings')
# ### end Alembic commands ###
@@ -0,0 +1,102 @@
"""Add delivery reliability and RSVP
Revision ID: 8c365be4d3a0
Revises: 5e84226bd650
Create Date: 2026-09-01 09:06:31.547215
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8c365be4d3a0'
down_revision = '5e84226bd650'
branch_labels = None
depends_on = None
def upgrade():
with op.batch_alter_table('audit_logs', schema=None) as batch_op:
batch_op.create_index('ix_audit_logs_action', ['action'], unique=False)
batch_op.create_index('ix_audit_logs_created_at', ['created_at'], unique=False)
batch_op.create_index('ix_audit_logs_username', ['username'], unique=False)
op.execute(sa.text(
"DELETE FROM check_ins WHERE id NOT IN "
"(SELECT MIN(id) FROM check_ins GROUP BY guest_id)"
))
with op.batch_alter_table('check_ins', schema=None) as batch_op:
batch_op.add_column(sa.Column('checked_in_by_id', sa.Integer(), nullable=True))
batch_op.create_index('ix_check_ins_event_time', ['event_id', 'checked_in_at'], unique=False)
batch_op.create_unique_constraint('uq_check_ins_guest_id', ['guest_id'])
batch_op.create_foreign_key('fk_check_ins_checked_in_by_id_users', 'users', ['checked_in_by_id'], ['id'])
with op.batch_alter_table('events', schema=None) as batch_op:
batch_op.add_column(sa.Column('event_end_date', sa.DateTime(), nullable=True))
batch_op.add_column(sa.Column('rsvp_enabled', sa.Boolean(), nullable=False, server_default=sa.true()))
batch_op.add_column(sa.Column('rsvp_deadline', sa.DateTime(), nullable=True))
batch_op.add_column(sa.Column('invitation_subject', sa.String(length=255), nullable=True))
batch_op.add_column(sa.Column('invitation_message', sa.Text(), nullable=True))
batch_op.create_index('ix_events_created_by_active', ['created_by_id', 'is_active'], unique=False)
batch_op.create_index('ix_events_event_date', ['event_date'], unique=False)
with op.batch_alter_table('guests', schema=None) as batch_op:
batch_op.add_column(sa.Column('invitation_status', sa.String(length=20), nullable=False, server_default='pending'))
batch_op.add_column(sa.Column('invitation_attempts', sa.Integer(), nullable=False, server_default='0'))
batch_op.add_column(sa.Column('invitation_last_error', sa.String(length=1000), nullable=True))
batch_op.add_column(sa.Column('invitation_last_attempt_at', sa.DateTime(), nullable=True))
batch_op.add_column(sa.Column('invitation_sent_at', sa.DateTime(), nullable=True))
batch_op.add_column(sa.Column('rsvp_status', sa.String(length=20), nullable=False, server_default='pending'))
batch_op.add_column(sa.Column('rsvp_responded_at', sa.DateTime(), nullable=True))
batch_op.add_column(sa.Column('rsvp_comment', sa.String(length=1000), nullable=True))
batch_op.add_column(sa.Column('dietary_requirements', sa.String(length=1000), nullable=True))
batch_op.create_index('ix_guests_event_active', ['event_id', 'is_active'], unique=False)
batch_op.create_index('ix_guests_event_email', ['event_id', 'email'], unique=False)
batch_op.create_index('ix_guests_event_full_name', ['event_id', 'full_name'], unique=False)
batch_op.create_index('ix_guests_event_rsvp', ['event_id', 'rsvp_status'], unique=False)
op.execute(sa.text("UPDATE guests SET invitation_status = 'sent' WHERE invitation_sent = true"))
with op.batch_alter_table('events', schema=None) as batch_op:
batch_op.alter_column('rsvp_enabled', server_default=None)
with op.batch_alter_table('guests', schema=None) as batch_op:
batch_op.alter_column('invitation_status', server_default=None)
batch_op.alter_column('invitation_attempts', server_default=None)
batch_op.alter_column('rsvp_status', server_default=None)
def downgrade():
with op.batch_alter_table('guests', schema=None) as batch_op:
batch_op.drop_index('ix_guests_event_rsvp')
batch_op.drop_index('ix_guests_event_full_name')
batch_op.drop_index('ix_guests_event_email')
batch_op.drop_index('ix_guests_event_active')
batch_op.drop_column('dietary_requirements')
batch_op.drop_column('rsvp_comment')
batch_op.drop_column('rsvp_responded_at')
batch_op.drop_column('rsvp_status')
batch_op.drop_column('invitation_sent_at')
batch_op.drop_column('invitation_last_attempt_at')
batch_op.drop_column('invitation_last_error')
batch_op.drop_column('invitation_attempts')
batch_op.drop_column('invitation_status')
with op.batch_alter_table('events', schema=None) as batch_op:
batch_op.drop_index('ix_events_event_date')
batch_op.drop_index('ix_events_created_by_active')
batch_op.drop_column('invitation_message')
batch_op.drop_column('invitation_subject')
batch_op.drop_column('rsvp_deadline')
batch_op.drop_column('rsvp_enabled')
batch_op.drop_column('event_end_date')
with op.batch_alter_table('check_ins', schema=None) as batch_op:
batch_op.drop_constraint('fk_check_ins_checked_in_by_id_users', type_='foreignkey')
batch_op.drop_constraint('uq_check_ins_guest_id', type_='unique')
batch_op.drop_index('ix_check_ins_event_time')
batch_op.drop_column('checked_in_by_id')
with op.batch_alter_table('audit_logs', schema=None) as batch_op:
batch_op.drop_index('ix_audit_logs_username')
batch_op.drop_index('ix_audit_logs_created_at')
batch_op.drop_index('ix_audit_logs_action')