Update registration Step

This commit is contained in:
Koncept Kit
2025-12-06 13:47:30 +07:00
parent a073fca0d7
commit 79b617904b
5 changed files with 165 additions and 2 deletions

View File

@@ -0,0 +1,69 @@
"""
Migration script to add multi-step registration fields to users table.
Run this once to update the database schema.
"""
from database import engine
from sqlalchemy import text
def add_multistep_registration_columns():
"""Add newsletter, volunteer, scholarship, and directory columns to users table"""
migrations = [
# Newsletter preferences
"ALTER TABLE users ADD COLUMN IF NOT EXISTS newsletter_publish_name BOOLEAN NOT NULL DEFAULT FALSE",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS newsletter_publish_photo BOOLEAN NOT NULL DEFAULT FALSE",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS newsletter_publish_birthday BOOLEAN NOT NULL DEFAULT FALSE",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS newsletter_publish_none BOOLEAN NOT NULL DEFAULT FALSE",
# Volunteer interests
"ALTER TABLE users ADD COLUMN IF NOT EXISTS volunteer_interests JSON DEFAULT '[]'::json",
# Scholarship
"ALTER TABLE users ADD COLUMN IF NOT EXISTS scholarship_requested BOOLEAN NOT NULL DEFAULT FALSE",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS scholarship_reason TEXT",
# Directory settings
"ALTER TABLE users ADD COLUMN IF NOT EXISTS show_in_directory BOOLEAN NOT NULL DEFAULT FALSE",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS directory_email VARCHAR",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS directory_bio TEXT",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS directory_address VARCHAR",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS directory_phone VARCHAR",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS directory_dob TIMESTAMP",
"ALTER TABLE users ADD COLUMN IF NOT EXISTS directory_partner_name VARCHAR"
]
try:
print("Adding multi-step registration columns to users table...")
with engine.connect() as conn:
for sql in migrations:
print(f" Executing: {sql[:70]}...")
conn.execute(text(sql))
conn.commit()
print("✅ Migration completed successfully!")
print("\nAdded columns:")
print(" Newsletter Preferences:")
print(" - newsletter_publish_name (BOOLEAN)")
print(" - newsletter_publish_photo (BOOLEAN)")
print(" - newsletter_publish_birthday (BOOLEAN)")
print(" - newsletter_publish_none (BOOLEAN)")
print(" Volunteer:")
print(" - volunteer_interests (JSON)")
print(" Scholarship:")
print(" - scholarship_requested (BOOLEAN)")
print(" - scholarship_reason (TEXT)")
print(" Directory:")
print(" - show_in_directory (BOOLEAN)")
print(" - directory_email (VARCHAR)")
print(" - directory_bio (TEXT)")
print(" - directory_address (VARCHAR)")
print(" - directory_phone (VARCHAR)")
print(" - directory_dob (TIMESTAMP)")
print(" - directory_partner_name (VARCHAR)")
except Exception as e:
print(f"❌ Migration failed: {e}")
raise
if __name__ == "__main__":
add_multistep_registration_columns()