From 80d22e05c44294fed20033edff93fa0240c04da0 Mon Sep 17 00:00:00 2001 From: Jens Luedicke Date: Wed, 2 Jul 2025 23:11:27 +0200 Subject: [PATCH] Fix DB migration/enum handling. --- MIGRATION_FREELANCERS.md | 6 +++--- app.py | 6 +++--- migrate_db.py | 2 +- migrate_freelancers.py | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/MIGRATION_FREELANCERS.md b/MIGRATION_FREELANCERS.md index cd33a58..df37547 100644 --- a/MIGRATION_FREELANCERS.md +++ b/MIGRATION_FREELANCERS.md @@ -13,7 +13,7 @@ The freelancer migration adds support for independent users who can register wit ## Database Changes ### User Table Changes -- `account_type` VARCHAR(20) DEFAULT 'Company User' - Type of account +- `account_type` VARCHAR(20) DEFAULT 'COMPANY_USER' - Type of account - `business_name` VARCHAR(100) - Optional business name for freelancers - `company_id` INTEGER - Foreign key to company table (for multi-tenancy) @@ -46,7 +46,7 @@ If you prefer manual control: ```sql -- Add columns to user table -ALTER TABLE user ADD COLUMN account_type VARCHAR(20) DEFAULT 'Company User'; +ALTER TABLE user ADD COLUMN account_type VARCHAR(20) DEFAULT 'COMPANY_USER'; ALTER TABLE user ADD COLUMN business_name VARCHAR(100); ALTER TABLE user ADD COLUMN company_id INTEGER; @@ -66,7 +66,7 @@ CREATE TABLE company ( ALTER TABLE company ADD COLUMN is_personal BOOLEAN DEFAULT 0; -- Update existing users -UPDATE user SET account_type = 'Company User' WHERE account_type IS NULL; +UPDATE user SET account_type = 'COMPANY_USER' WHERE account_type IS NULL; ``` ## Post-Migration Steps diff --git a/app.py b/app.py index 4847094..9f63a1c 100644 --- a/app.py +++ b/app.py @@ -160,7 +160,7 @@ def run_migrations(): ('team_id', "ALTER TABLE user ADD COLUMN team_id INTEGER"), ('two_factor_enabled', "ALTER TABLE user ADD COLUMN two_factor_enabled BOOLEAN DEFAULT 0"), ('two_factor_secret', "ALTER TABLE user ADD COLUMN two_factor_secret VARCHAR(32)"), - ('account_type', "ALTER TABLE user ADD COLUMN account_type VARCHAR(20) DEFAULT 'Company User'"), + ('account_type', "ALTER TABLE user ADD COLUMN account_type VARCHAR(20) DEFAULT 'COMPANY_USER'"), ('business_name', "ALTER TABLE user ADD COLUMN business_name VARCHAR(100)") ] @@ -196,7 +196,7 @@ def run_migrations(): team_id INTEGER, two_factor_enabled BOOLEAN DEFAULT 0, two_factor_secret VARCHAR(32), - account_type VARCHAR(20) DEFAULT 'Company User', + account_type VARCHAR(20) DEFAULT 'COMPANY_USER', business_name VARCHAR(100), company_id INTEGER ) @@ -210,7 +210,7 @@ def run_migrations(): SELECT id, username, email, password_hash, created_at, is_verified, verification_token, token_expiry, is_blocked, role, team_id, two_factor_enabled, two_factor_secret, - COALESCE(account_type, 'Company User'), + COALESCE(account_type, 'COMPANY_USER'), business_name, company_id FROM user diff --git a/migrate_db.py b/migrate_db.py index 937decf..beb7adb 100644 --- a/migrate_db.py +++ b/migrate_db.py @@ -120,7 +120,7 @@ def migrate_database(): # Add freelancer support columns to user table if 'account_type' not in user_columns: print("Adding account_type column to user table...") - cursor.execute("ALTER TABLE user ADD COLUMN account_type VARCHAR(20) DEFAULT 'Company User'") + cursor.execute("ALTER TABLE user ADD COLUMN account_type VARCHAR(20) DEFAULT 'COMPANY_USER'") if 'business_name' not in user_columns: print("Adding business_name column to user table...") diff --git a/migrate_freelancers.py b/migrate_freelancers.py index 180ff61..80666c1 100644 --- a/migrate_freelancers.py +++ b/migrate_freelancers.py @@ -52,8 +52,8 @@ def migrate_freelancer_support(): # Add account_type column to user table if it doesn't exist if 'account_type' not in user_columns: print("Adding account_type column to user table...") - # Default to 'Company User' for existing users - cursor.execute("ALTER TABLE user ADD COLUMN account_type VARCHAR(20) DEFAULT 'Company User'") + # Default to 'COMPANY_USER' for existing users + cursor.execute("ALTER TABLE user ADD COLUMN account_type VARCHAR(20) DEFAULT 'COMPANY_USER'") # Add business_name column to user table if it doesn't exist if 'business_name' not in user_columns: @@ -65,8 +65,8 @@ def migrate_freelancer_support(): print("✓ Freelancer migration completed successfully!") # Update existing users to have explicit account_type - print("Updating existing users to Company User account type...") - cursor.execute("UPDATE user SET account_type = 'Company User' WHERE account_type IS NULL OR account_type = ''") + print("Updating existing users to COMPANY_USER account type...") + cursor.execute("UPDATE user SET account_type = 'COMPANY_USER' WHERE account_type IS NULL OR account_type = ''") conn.commit() return True