Fix for DB Migration. #3
This commit is contained in:
14
app.py
14
app.py
@@ -381,6 +381,18 @@ def run_migrations():
|
|||||||
if updated_count > 0:
|
if updated_count > 0:
|
||||||
print(f"Updated {updated_count} users from '{old_role}' to '{new_role}'")
|
print(f"Updated {updated_count} users from '{old_role}' to '{new_role}'")
|
||||||
|
|
||||||
|
# Also normalize account_type values
|
||||||
|
account_type_mapping = {
|
||||||
|
'COMPANY_USER': 'Company User',
|
||||||
|
'FREELANCER': 'Freelancer'
|
||||||
|
}
|
||||||
|
|
||||||
|
for old_type, new_type in account_type_mapping.items():
|
||||||
|
cursor.execute("UPDATE user SET account_type = ? WHERE account_type = ?", (new_type, old_type))
|
||||||
|
updated_count = cursor.rowcount
|
||||||
|
if updated_count > 0:
|
||||||
|
print(f"Updated {updated_count} users account_type from '{old_type}' to '{new_type}'")
|
||||||
|
|
||||||
# Set any NULL roles to default
|
# Set any NULL roles to default
|
||||||
cursor.execute("UPDATE user SET role = 'Team Member' WHERE role IS NULL")
|
cursor.execute("UPDATE user SET role = 'Team Member' WHERE role IS NULL")
|
||||||
null_updated = cursor.rowcount
|
null_updated = cursor.rowcount
|
||||||
@@ -405,7 +417,7 @@ def run_migrations():
|
|||||||
is_blocked BOOLEAN DEFAULT 0,
|
is_blocked BOOLEAN DEFAULT 0,
|
||||||
role VARCHAR(50) DEFAULT 'Team Member' CHECK (role IN ('Team Member', 'Team Leader', 'Supervisor', 'Administrator', 'System Administrator')),
|
role VARCHAR(50) DEFAULT 'Team Member' CHECK (role IN ('Team Member', 'Team Leader', 'Supervisor', 'Administrator', 'System Administrator')),
|
||||||
team_id INTEGER,
|
team_id INTEGER,
|
||||||
account_type VARCHAR(20) DEFAULT 'COMPANY_USER',
|
account_type VARCHAR(20) DEFAULT 'Company User' CHECK (account_type IN ('Company User', 'Freelancer')),
|
||||||
business_name VARCHAR(100),
|
business_name VARCHAR(100),
|
||||||
two_factor_enabled BOOLEAN DEFAULT 0,
|
two_factor_enabled BOOLEAN DEFAULT 0,
|
||||||
two_factor_secret VARCHAR(32),
|
two_factor_secret VARCHAR(32),
|
||||||
|
|||||||
@@ -141,11 +141,11 @@ class User(db.Model):
|
|||||||
is_blocked = db.Column(db.Boolean, default=False)
|
is_blocked = db.Column(db.Boolean, default=False)
|
||||||
|
|
||||||
# New fields for role and team
|
# New fields for role and team
|
||||||
role = db.Column(db.Enum(Role), default=Role.TEAM_MEMBER)
|
role = db.Column(db.Enum(Role, values_callable=lambda obj: [e.value for e in obj]), default=Role.TEAM_MEMBER)
|
||||||
team_id = db.Column(db.Integer, db.ForeignKey('team.id'), nullable=True)
|
team_id = db.Column(db.Integer, db.ForeignKey('team.id'), nullable=True)
|
||||||
|
|
||||||
# Freelancer support
|
# Freelancer support
|
||||||
account_type = db.Column(db.Enum(AccountType), default=AccountType.COMPANY_USER)
|
account_type = db.Column(db.Enum(AccountType, values_callable=lambda obj: [e.value for e in obj]), default=AccountType.COMPANY_USER)
|
||||||
business_name = db.Column(db.String(100), nullable=True) # Optional business name for freelancers
|
business_name = db.Column(db.String(100), nullable=True) # Optional business name for freelancers
|
||||||
|
|
||||||
# Unique constraints per company
|
# Unique constraints per company
|
||||||
|
|||||||
Reference in New Issue
Block a user