U
    [Mh                  
   @   s  d Z ddlmZmZ ddlmZ ddlZddlmZmZ ed e	dZ
ed zee
Ze hZed	ZeeZd
d eD Zede  dekred edZeeZe Zed eD ]6Zeded  ded  ded dkrdnd  qed edZee edZee ddgZeD ]Zeee q@e  ed ed eed Ze ZeD ]:Zeded  ded  ded dkrdnd  qed! W 5 Q R X W n2 ek
r
 Z zed"e  W 5 dZ[X Y nX dS )#zH
Complete Solution: Create/Update developers table and fix registration
    )create_enginetext)load_dotenvN)datetimetimezonez
.env.localDATABASE_URLu,   🔧 Setting up developers table properly...z~
            SELECT table_name 
            FROM information_schema.tables 
            WHERE table_schema = 'public'
        c                 C   s   g | ]}|d  qS )r    ).0rowr   r   ./setup_developers_table.py
<listcomp>   s     r   u   📋 Existing tables: Z
developersu4   
🔍 Checking current developers table structure...z
                SELECT column_name, data_type, is_nullable, column_default
                FROM information_schema.columns 
                WHERE table_name = 'developers'
                ORDER BY ordinal_position
            zCurrent columns:z   - z (   z) -    ZYESZNULLzNOT NULLu?   
🔨 Creating/updating developers table to match your model...z'DROP TABLE IF EXISTS developers CASCADEa  
            CREATE TABLE developers (
                id SERIAL PRIMARY KEY,
                developer_id VARCHAR UNIQUE,
                name VARCHAR,
                email VARCHAR,
                active BOOLEAN DEFAULT TRUE,
                api_token VARCHAR UNIQUE,
                created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
                last_sync TIMESTAMP WITH TIME ZONE
            )
        zRCREATE INDEX IF NOT EXISTS ix_developers_developer_id ON developers (developer_id)zLCREATE INDEX IF NOT EXISTS ix_developers_api_token ON developers (api_token)u*   ✅ Developers table created successfully!u   
📋 New table structure:z
            SELECT column_name, data_type, is_nullable, column_default
            FROM information_schema.columns 
            WHERE table_name = 'developers'
            ORDER BY ordinal_position
        u   
🎉 Database setup complete!u   ❌ Error: )__doc__Z
sqlalchemyr   r   Zdotenvr   osr   r   getenvr   printZengineZconnectZconnZtables_queryZexecuteresultZexisting_tablesZcolumns_queryZfetchallcolumnscolZ
drop_tableZcreate_tableZindexesidxZcommit	Exceptioner   r   r   r   <module>   sT   



4

8