U
    [Mhr                     @   s   d Z ddlZddlmZmZ ddlmZ ddlZddlm	Z	 e  dd Z
edkred	 ed
 edZe dkre
 red qed ned dS )z=
Script to fix the users table for the timesheet application
    N)create_enginetext)load_dotenv)Basec                  C   s&  t d} t| }z| }| }z*td |td td |  W nJ t	k
r } z,|
  td|  W Y W 5 Q R  W dS d}~X Y nX W 5 Q R X td tjj|d	 td
 td td td td W dS  t	k
r  } ztd|  W Y dS d}~X Y nX dS )z.Rename existing users table and create our ownZDATABASE_URLu5   🔄 Renaming existing users table to users_backup...z(ALTER TABLE users RENAME TO users_backupu4   ✅ Existing users table backed up as 'users_backup'u   ❌ Error renaming table: FNu2   🆕 Creating new users table for timesheet app...)Zbindu)   ✅ New users table created successfully!u   
🎯 Next steps:z;1. Your original users data is safe in 'users_backup' tablez72. You can now register new users for the timesheet appz:3. If needed, you can migrate data from users_backup laterTu   ❌ Error: )osgetenvr   ZconnectZbeginprintZexecuter   Zcommit	ExceptionZrollbackr   ZmetadataZ
create_all)Zdatabase_urlZengineZconnZtranse r   ./fix_users_table.pyfix_users_table   s2    

.r   __main__z)Users Table Fix for Timesheet Applicationz2==================================================z|This will rename your existing 'users' table to 'users_backup' and create a new one for the timesheet app. Continue? (y/N): yu%   
🎉 Users table fixed successfully!u   
❌ Failed to fix users tablezOperation cancelled.)__doc__r   Z
sqlalchemyr   r   Zdotenvr   ZmodelsZdatabaser   r   __name__r   inputZresponselowerr   r   r   r   <module>   s    (

