mirror of
https://github.com/DarkflameUniverse/NexusDashboard.git
synced 2024-08-30 18:12:11 +00:00
autdit log model
This commit is contained in:
parent
f0cbcee100
commit
91e6ed33e7
@ -1002,6 +1002,46 @@ class Reports(db.Model):
|
||||
autoincrement=False
|
||||
)
|
||||
|
||||
def save(self):
|
||||
db.session.add(self)
|
||||
db.session.commit()
|
||||
db.session.refresh(self)
|
||||
|
||||
def delete(self):
|
||||
db.session.delete(self)
|
||||
db.session.commit()
|
||||
|
||||
class AuditLog(db.Model):
|
||||
__tablename__ = 'audit_logs'
|
||||
id = db.Column(
|
||||
mysql.INTEGER,
|
||||
primary_key=True
|
||||
)
|
||||
|
||||
account_id = db.Column(
|
||||
db.Integer(),
|
||||
db.ForeignKey(Account.id, ondelete='CASCADE'),
|
||||
nullable=True
|
||||
)
|
||||
|
||||
account = db.relationship(
|
||||
'Account',
|
||||
backref="audit_logs",
|
||||
passive_deletes=True
|
||||
)
|
||||
|
||||
action = db.Column(
|
||||
mysql.TEXT,
|
||||
nullable=True
|
||||
)
|
||||
|
||||
date = db.Column(
|
||||
mysql.TIMESTAMP,
|
||||
nullable=False,
|
||||
server_default=db.func.now()
|
||||
)
|
||||
|
||||
|
||||
def save(self):
|
||||
db.session.add(self)
|
||||
db.session.commit()
|
||||
|
35
migrations/versions/f56ee94c179e_add_audio_log_table.py
Normal file
35
migrations/versions/f56ee94c179e_add_audio_log_table.py
Normal file
@ -0,0 +1,35 @@
|
||||
"""Add audio_log table
|
||||
|
||||
Revision ID: f56ee94c179e
|
||||
Revises: aee4c6c24811
|
||||
Create Date: 2022-02-11 21:28:29.595665
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'f56ee94c179e'
|
||||
down_revision = 'aee4c6c24811'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('audit_logs',
|
||||
sa.Column('id', mysql.INTEGER(), nullable=False),
|
||||
sa.Column('account_id', sa.Integer(), nullable=True),
|
||||
sa.Column('action', mysql.TEXT(), nullable=True),
|
||||
sa.Column('date', mysql.TIMESTAMP(), server_default=sa.text('now()'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['account_id'], ['accounts.id'], ondelete='CASCADE'),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('audit_logs')
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user