Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added admin tables used in admin app to namex model/db #533

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions api/migrations/versions/ffcd16e0e2f5_admin_tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""empty message

Revision ID: ffcd16e0e2f5
Revises: 21b953f6b653
Create Date: 2019-02-22 15:42:29.801061

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'ffcd16e0e2f5'
down_revision = '21b953f6b653'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('decision_reason_audit',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('username', sa.String(length=100), nullable=True),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('action', sa.String(length=10), nullable=True),
sa.Column('dr_id', sa.Integer(), nullable=True),
sa.Column('name', sa.VARCHAR(length=1024), nullable=True),
sa.Column('reason', sa.VARCHAR(length=1024), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('restricted_condition_audit',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('username', sa.String(length=100), nullable=True),
sa.Column('timestamp', sa.DateTime(), nullable=True),
sa.Column('action', sa.String(length=10), nullable=True),
sa.Column('cnd_id', sa.Integer(), nullable=True),
sa.Column('consenting_body', sa.VARCHAR(length=195), nullable=True),
sa.Column('words', sa.VARCHAR(length=1000), nullable=True),
sa.Column('cnd_text', sa.String(length=1000), nullable=True),
sa.Column('instructions', sa.VARCHAR(length=1000), nullable=True),
sa.Column('consent_required', sa.Boolean(), nullable=True),
sa.Column('allow_use', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('virtual_word_condition',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.Column('rc_consenting_body', sa.VARCHAR(length=195), nullable=True),
sa.Column('rc_words', sa.VARCHAR(length=1000), nullable=True),
sa.Column('rc_condition_text', sa.VARCHAR(length=1000), nullable=True),
sa.Column('rc_instructions', sa.VARCHAR(length=1000), nullable=True),
sa.Column('rc_consent_required', sa.Boolean(), nullable=True),
sa.Column('rc_allow_use', sa.Boolean(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('virtual_word_condition')
op.drop_table('restricted_condition_audit')
op.drop_table('decision_reason_audit')
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions api/namex/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
from .state import State, StateSchema
from .decision_reason import DecisionReason
from .nro_sync_tables import NRONamesSyncJob, NRONamesSyncJobDetail, NRONamesSyncJobStatus
from .admin_tables import DecisionReasonAudit, RestrictedConditionAudit, VirtualWordCondition
79 changes: 79 additions & 0 deletions api/namex/models/admin_tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import datetime
from . import db
from sqlalchemy.schema import Column


def _to_string(string):
if string is None:
return ''

return string


class VirtualWordCondition(db.Model):
__tablename__ = 'virtual_word_condition'

id = Column(db.Integer, primary_key=True, autoincrement=True)

rc_consenting_body = Column(db.VARCHAR(195))
rc_words = Column(db.VARCHAR(1000))
rc_condition_text = Column(db.VARCHAR(1000))
rc_instructions = Column(db.VARCHAR(1000))
rc_consent_required = db.Column(db.Boolean(), default=False)
rc_allow_use = db.Column(db.Boolean(), default=True)


# The class that corresponds to the database table for decision reasons audits.
class DecisionReasonAudit(db.Model):
__tablename__ = 'decision_reason_audit'

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(100))
timestamp = db.Column(db.DateTime)
action = db.Column(db.String(10))
dr_id = db.Column(db.Integer)
name = db.Column(db.VARCHAR(1024))
reason = db.Column(db.VARCHAR(1024))

def __init__(
self, username: str, action: str, id: str,
name: str, reason: str) -> None:
self.username = username
self.timestamp = datetime.datetime.now()
self.action = action
self.dr_id = id
self.name = name
self.reason = reason


# The class that corresponds to the database table for restricted condition audits.
class RestrictedConditionAudit(db.Model):
__tablename__ = 'restricted_condition_audit'

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
username = db.Column(db.String(100))
timestamp = db.Column(db.DateTime)
action = db.Column(db.String(10))
cnd_id = db.Column(db.Integer)
consenting_body = db.Column(db.VARCHAR(195))
words = db.Column(db.VARCHAR(1000))
cnd_text = db.Column(db.String(1000))
instructions = db.Column(db.VARCHAR(1000))
consent_required = db.Column(db.Boolean(), default=True)
allow_use = db.Column(db.Boolean(), default=True)

def __init__(
self, username: str, action: str, cnd_id: int, cnd_text: str, words: str,
consent_required: bool, consenting_body: str, instructions: str,
allow_use: bool) -> None:
self.username = username
self.timestamp = datetime.datetime.now()
self.action = action
self.cnd_id = cnd_id
self.cnd_text = cnd_text
self.words = words
self.consent_required = consent_required
self.consenting_body = consenting_body
self.instructions = instructions
self.allow_use = allow_use