1+ """fix auditoria idempotente
2+
3+ Revision ID: 4db4f85650c4
4+ Revises: f0898c3bfea6
5+ Create Date: 2025-07-15 01:28:33.088174
6+
7+ """
8+
9+ from alembic import op
10+ import sqlalchemy as sa
11+ from sqlalchemy import inspect
12+
13+ # revision identifiers, used by Alembic.
14+ revision = '4db4f85650c4'
15+ down_revision = 'f0898c3bfea6'
16+ branch_labels = None
17+ depends_on = None
18+
19+ def upgrade ():
20+ conn = op .get_bind ()
21+ inspector = inspect (conn )
22+ if "auditoria" not in inspector .get_table_names ():
23+ op .create_table (
24+ "auditoria" ,
25+ sa .Column ("id" , sa .Integer (), primary_key = True , autoincrement = True ),
26+ sa .Column ('usuario_id' , sa .Integer ()),
27+ sa .Column ('username' , sa .String (length = 150 ), nullable = True ),
28+ sa .Column ('acao' , sa .String (length = 100 ), nullable = False ),
29+ sa .Column ('entidade' , sa .String (length = 100 ), nullable = True ),
30+ sa .Column ('valor_anterior' , sa .Text (), nullable = True ),
31+ sa .Column ('valor_novo' , sa .Text (), nullable = True ),
32+ sa .Column ('detalhes' , sa .Text (), nullable = True ),
33+ sa .Column ('ip' , sa .String (length = 45 ), nullable = True ),
34+ sa .Column ('data_hora' , sa .DateTime (), nullable = True ),
35+ sa .ForeignKeyConstraint (['usuario_id' ], ['usuario.id' ]),
36+ )
37+
38+ def downgrade ():
39+ op .drop_table ("auditoria" )
0 commit comments