Add updated and created at fields for tables
parent
d71aca4b8c
commit
584697e58e
|
@ -129,6 +129,13 @@ class Role(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
display_name = db.Column(db.String, unique=True)
|
display_name = db.Column(db.String, unique=True)
|
||||||
permissions = db.Column(db.ARRAY(db.String))
|
permissions = db.Column(db.ARRAY(db.String))
|
||||||
|
created_at = db.Column(db.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
default=db.func.current_timestamp())
|
||||||
|
modified_at = db.Column(db.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
default=db.func.current_timestamp(),
|
||||||
|
onupdate=db.func.current_timestamp())
|
||||||
|
|
||||||
def __init__(self, name, permissions):
|
def __init__(self, name, permissions):
|
||||||
self.display_name = str(name)
|
self.display_name = str(name)
|
||||||
|
|
|
@ -225,6 +225,13 @@ class DeviceAssociation(db.Model):
|
||||||
primary_key=True)
|
primary_key=True)
|
||||||
access_level = db.Column(db.Integer, db.ForeignKey('access_levels.id'),
|
access_level = db.Column(db.Integer, db.ForeignKey('access_levels.id'),
|
||||||
nullable=False)
|
nullable=False)
|
||||||
|
created_at = db.Column(db.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
default=db.func.current_timestamp())
|
||||||
|
modified_at = db.Column(db.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
default=db.func.current_timestamp(),
|
||||||
|
onupdate=db.func.current_timestamp())
|
||||||
|
|
||||||
access_level_data = db.relationship("AccessLevel",
|
access_level_data = db.relationship("AccessLevel",
|
||||||
foreign_keys=[access_level])
|
foreign_keys=[access_level])
|
||||||
|
@ -279,6 +286,13 @@ class DeviceType(db.Model):
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
name = db.Column(db.String, nullable=False)
|
||||||
|
created_at = db.Column(db.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
default=db.func.current_timestamp())
|
||||||
|
modified_at = db.Column(db.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
default=db.func.current_timestamp(),
|
||||||
|
onupdate=db.func.current_timestamp())
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -333,6 +347,13 @@ class AccessLevel(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
name = db.Column(db.String, nullable=False)
|
name = db.Column(db.String, nullable=False)
|
||||||
permissions = db.Column(db.ARRAY(db.String), nullable=False)
|
permissions = db.Column(db.ARRAY(db.String), nullable=False)
|
||||||
|
created_at = db.Column(db.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
default=db.func.current_timestamp())
|
||||||
|
modified_at = db.Column(db.DateTime,
|
||||||
|
nullable=False,
|
||||||
|
default=db.func.current_timestamp(),
|
||||||
|
onupdate=db.func.current_timestamp())
|
||||||
|
|
||||||
def __init__(self, name, permissions=['VIEW_DEVICE']):
|
def __init__(self, name, permissions=['VIEW_DEVICE']):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 764de3c39771
|
||||||
|
Revises: 43e5ad1c4393
|
||||||
|
Create Date: 2018-11-03 15:00:36.463124
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '764de3c39771'
|
||||||
|
down_revision = '43e5ad1c4393'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('access_levels', sa.Column('created_at', sa.DateTime(),
|
||||||
|
nullable=False, server_default=sa.func.current_timestamp()))
|
||||||
|
op.add_column('access_levels', sa.Column('modified_at', sa.DateTime(),
|
||||||
|
nullable=False, server_default=sa.func.current_timestamp()))
|
||||||
|
op.add_column('device_associations', sa.Column('created_at', sa.DateTime(),
|
||||||
|
nullable=False, server_default=sa.func.current_timestamp()))
|
||||||
|
op.add_column('device_associations', sa.Column('modified_at',
|
||||||
|
sa.DateTime(), nullable=False,
|
||||||
|
server_default=sa.func.current_timestamp()))
|
||||||
|
op.add_column('device_types', sa.Column('created_at', sa.DateTime(),
|
||||||
|
nullable=False, server_default=sa.func.current_timestamp()))
|
||||||
|
op.add_column('device_types', sa.Column('modified_at', sa.DateTime(),
|
||||||
|
nullable=False, server_default=sa.func.current_timestamp()))
|
||||||
|
op.add_column('roles', sa.Column('created_at', sa.DateTime(),
|
||||||
|
nullable=False, server_default=sa.func.current_timestamp()))
|
||||||
|
op.add_column('roles', sa.Column('modified_at', sa.DateTime(),
|
||||||
|
nullable=False, server_default=sa.func.current_timestamp()))
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('roles', 'modified_at')
|
||||||
|
op.drop_column('roles', 'created_at')
|
||||||
|
op.drop_column('device_types', 'modified_at')
|
||||||
|
op.drop_column('device_types', 'created_at')
|
||||||
|
op.drop_column('device_associations', 'modified_at')
|
||||||
|
op.drop_column('device_associations', 'created_at')
|
||||||
|
op.drop_column('access_levels', 'modified_at')
|
||||||
|
op.drop_column('access_levels', 'created_at')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in New Issue