class Customers(db.Model): __tablename__ = 'customers' MALE = 'M' FEMALE = 'F' GENDERS = [ (MALE, 'Male'), (FEMALE, 'Female'), ] customerid = db.Column(db.Integer, primary_key=True) firstname = db.Column(db.String(50), info={'anonymize': True}) lastname = db.Column(db.String(50), info={'anonymize': True}) address1 = db.Column(db.String(50), info={'anonymize': True}) address2 = db.Column(db.String(50), info={'anonymize': True}) city = db.Column(db.String(50), info={'anonymize': True}) state = db.Column(db.String(50), info={'anonymize': True}) zip = db.Column(db.Integer, info={'anonymize': True}) country = db.Column(su.CountryType) region = db.Column(db.Integer) email = db.Column(su.EmailType(50), unique=True) phone = db.Column(su.PhoneNumberType(max_length=50), unique=True) creditcardtype = db.Column(db.Integer, info={'anonymize': True}) creditcard = db.Column(db.String(50), info={'anonymize': True}) creditcardexpiration = db.Column(db.String(50), info={'anonymize': True}) username = db.Column(db.String(50), info={'anonymize': True}) password = db.Column(su.PasswordType(schemes=['pbkdf2_sha512'])) age = db.Column(db.Integer, info={'anonymize': True}) income = db.Column(db.Integer, info={'anonymize': True}) gender = db.Column(su.ChoiceType(GENDERS, impl=db.String(1))) _deleted_at = db.Column('deleted_at', db.DateTime) shopping_history = db.relationship('Orders', secondary='cust_hist') @property def is_active(self): return self._deleted_at is None @classmethod def from_form(cls, form): """Retorna um novo Customer a partir de um form""" customer = cls() form.populate_obj(customer) return customer def anonymized(self): """Anonimiza informacoes que identificam uma pessoa""" self._deleted_at = datetime.now() self.phone = self.phone and mask(self.phone.e164[1:], 5, 0) self.email = self.email and \ mask(self.email, pattern=mask.EMAIL_ANONYMIZATION, n_mask_char=2) self.password = None for column in self.__table__.columns: if column.info.get('anonymize'): setattr(self, column.name, None) return self
class User(Base, sau.Timestamp): __tablename__ = 'conduit_api_user' # base fields uuid = sa.Column('uuid', sau.UUIDType(binary=False), primary_key=True, nullable=False, unique=True, default=uuid.uuid4()) email = sa.Column( 'email', sau.EmailType, nullable=False, unique=True, ) username = sa.Column('username', sa.String(20), nullable=False) password = sa.Column('password', sau.PasswordType(schemes=[ 'pbkdf2_sha512', ], ), nullable=False) bio = sa.Column('bio', sa.String(100), nullable=True) image = sa.Column('image', sau.URLType, nullable=True) # relationship fields profile = relationship('Profile', uselist=False, back_populates='conduit_api_profile') __manager__ = UserManager() def __repr__(self): return '<User email: {}, username: {} >'.format( self.email, self.username) def __str__(self): return 'Conduit API User Model' def serialize(self): """ returns JSON-serialized format of Model """ return { 'email': self.email, 'username': self.username, 'bio': self.bio, 'image': self.image }
def upgrade(): op.create_table( 'builtin_users', sa.Column('id', sau.UUIDType, server_default=sa.text("uuid_generate_v4()"), primary_key=True), sa.Column('username', sa.String, nullable=False, unique=True), sa.Column('password', sau.PasswordType(schemes=['bcrypt']), nullable=False), sa.Column('roles', ARRAY(sa.String), default=list), sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), nullable=False, index=True), sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), onupdate=sa.text('clock_timestamp()'), nullable=False))
class User(TimestampMixin, Model): __tablename__ = 'user' id = db.Column(db.BigInteger(), primary_key=True) username = db.Column(db.Unicode(128), nullable=False) password = db.Column( sau.PasswordType(schemes=['bcrypt'], bcrypt__min_rounds=12)) def __str__(self): return self.username # Stuff for flask login @staticmethod @login_manager.user_loader def flask_login__load_user(user_id): try: return User.query.get(int(user_id)) except (ValueError, TypeError): pass return None @property def is_authenticated(self): return True @property def is_active(self): return True @property def is_anonymous(self): return False def get_id(self): return str(self.id)
class SecretSanity(db.Model): id = sa.Column(sa.Integer, primary_key=True) secret = sa.Column(sau.PasswordType(schemes=['pbkdf2_sha512']), nullable=False)
def upgrade(): conn = op.get_bind() inspector = Inspector.from_engine(conn) tables = inspector.get_table_names() if 'user_type' not in tables: op.create_table( 'user_type', sa.Column('id', sa.Integer, primary_key=True, autoincrement=True), sa.Column('alias', sa.String(32), nullable=False), sa.Column('title', sa.String(32), nullable=False), sa.Column('comment_limit', sa.Integer, nullable=True), sa.Column('created_at', sa.DateTime, nullable=False, server_default=sa.func.now()), sa.Column('updated_at', sa.DateTime, nullable=False, server_default=sa.func.now())) if 'user' not in tables: op.create_table( 'user', sa.Column('id', sa.Integer, primary_key=True, autoincrement=True), sa.Column('phone', sa.String(16), nullable=False, unique=True), sa.Column('password', su.PasswordType(schemes=['pbkdf2_sha512', 'md5_crypt'], deprecated=['md5_crypt']), nullable=False), sa.Column('nickname', sa.String(64), nullable=False, unique=True), sa.Column('first_name', sa.String(32), nullable=False), sa.Column('last_name', sa.String(32), nullable=False), sa.Column('avatar', sa.String(128), nullable=True), sa.Column('user_type_id', sa.Integer, sa.ForeignKey('user_type.id'), index=True, nullable=False), sa.Column('account_active_to', sa.DateTime, nullable=True), sa.Column('birth_date', sa.DateTime, nullable=False), sa.Column('created_at', sa.DateTime, nullable=False, server_default=sa.func.now()), sa.Column('updated_at', sa.DateTime, nullable=False, server_default=sa.func.now())) if 'tag' not in tables: op.create_table( 'tag', sa.Column('id', sa.Integer, primary_key=True, autoincrement=True), sa.Column('title', sa.String(64), nullable=False), sa.Column('is_active', sa.Boolean, default=True), sa.Column('created_at', sa.DateTime, nullable=False, server_default=sa.func.now()), sa.Column('updated_at', sa.DateTime, nullable=False, server_default=sa.func.now())) if 'post' not in tables: op.create_table( 'post', sa.Column('id', sa.Integer, primary_key=True, autoincrement=True), sa.Column('title', sa.String(128), nullable=False), sa.Column('text', sa.Text, nullable=False), sa.Column('preview_text', sa.String(300), nullable=False), sa.Column('cover', sa.String(64), nullable=True), sa.Column('author_id', sa.Integer, sa.ForeignKey('user.id'), index=True, nullable=False), sa.Column('created_at', sa.DateTime, nullable=False, server_default=sa.func.now()), sa.Column('updated_at', sa.DateTime, nullable=False, server_default=sa.func.now())) if 'comment' not in tables: op.create_table( 'comment', sa.Column('id', sa.Integer, primary_key=True, autoincrement=True), sa.Column('text', sa.String(512), nullable=False), sa.Column('author_id', sa.Integer, sa.ForeignKey('user.id'), index=True, nullable=False), sa.Column('post_id', sa.Integer, sa.ForeignKey('post.id'), index=True, nullable=False), sa.Column('parent_comment', sa.Integer, nullable=True), sa.Column('created_at', sa.DateTime, nullable=False, server_default=sa.func.now()), sa.Column('updated_at', sa.DateTime, nullable=False, server_default=sa.func.now())) if 'post_tag' not in tables: op.create_table( 'post_tag', sa.Column('id', sa.Integer, primary_key=True, autoincrement=True), sa.Column('post_id', sa.Integer, sa.ForeignKey('post.id'), index=True, nullable=False), sa.Column('tag_id', sa.Integer, sa.ForeignKey('tag.id'), index=True, nullable=False), sa.Column('created_at', sa.DateTime, nullable=False, server_default=sa.func.now()), sa.Column('updated_at', sa.DateTime, nullable=False, server_default=sa.func.now()))
import arrow import sqlalchemy_utils as sau from . import db from ..settings import PASSWORD_SCHEMES PasswordType = sau.PasswordType(schemes=PASSWORD_SCHEMES) class User(db.Model): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True, doc='User ID') email = db.Column(db.String(64), nullable=False, doc='User email') password = db.Column(PasswordType, nullable=False, doc='User password') registered_at = db.Column(sau.ArrowType, default=arrow.utcnow, doc='User registration date') is_active = db.Column(db.Boolean, nullable=False, default=True, doc='Is the user active?') pseudo = db.Column(db.String(32), nullable=False, doc='User pseudo') city = db.Column(db.String(255), nullable=True, doc='User city') birth_date = db.Column(db.Date, nullable=True, doc='User Birth Date') gender = db.Column(db.Enum('female', 'male', 'other', name='gender_types'), nullable=True,
def upgrade(): op.create_table( 'tbl_clinics', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.Unicode(128), nullable=False), sa.Column('canonical_id', sa.Integer(), nullable=True), sa.Column('is_active', sa.Boolean(), nullable=False), sa.ForeignKeyConstraint( ['canonical_id'], ['tbl_clinics.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name')) op.create_index(op.f('ix_tbl_clinics_canonical_id'), 'tbl_clinics', ['canonical_id'], unique=False) op.create_table( 'tbl_patients', sa.Column('ptnum', sa.Integer(), nullable=False), sa.Column('lastname', sa.Unicode(128), nullable=False), sa.Column('firstname', sa.Unicode(128), nullable=False), sa.Column('birthday', sa.Date(), nullable=True), sa.Column('hivdb_ptid', sa.Integer(), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), nullable=False), sa.PrimaryKeyConstraint('ptnum')) op.create_index(op.f('ix_tbl_patients_created_at'), 'tbl_patients', ['created_at'], unique=False) op.create_index(op.f('ix_tbl_patients_firstname'), 'tbl_patients', ['firstname'], unique=False) op.create_index(op.f('ix_tbl_patients_hivdb_ptid'), 'tbl_patients', ['hivdb_ptid'], unique=False) op.create_index('patient_name_index', 'tbl_patients', ['lastname', 'firstname'], unique=False) op.create_table('tbl_physicians', sa.Column('id', sa.Integer(), nullable=False), sa.Column('lastname', sa.Unicode(128), nullable=False), sa.Column('firstname', sa.Unicode(128), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('lastname', 'firstname')) op.create_index(op.f('ix_tbl_physicians_firstname'), 'tbl_physicians', ['firstname'], unique=False) op.create_index(op.f('ix_tbl_physicians_lastname'), 'tbl_physicians', ['lastname'], unique=False) op.create_table( 'tbl_reports', sa.Column('id', sa.Integer(), nullable=False), sa.Column('content', UploadedFileField(), nullable=True), sa.Column('content_type', sa.Unicode(16), nullable=True), sa.Column('status', sa.Unicode(32), nullable=True), sa.Column('created_at', sa.DateTime(timezone=True), nullable=True), sa.PrimaryKeyConstraint('id')) op.create_table('tbl_sequences', sa.Column('id', sa.Integer(), nullable=False), sa.Column('naseq', sa.Text(), nullable=False), sa.Column('subtype', sa.Unicode(64), nullable=False), sa.Column('genes', sau.ScalarListType(), nullable=False), sa.Column('filename', sa.Unicode(256), nullable=True), sa.PrimaryKeyConstraint('id')) op.create_table( 'tbl_users', sa.Column('id', sa.Integer(), nullable=False), sa.Column('email', sau.EmailType(), nullable=False), sa.Column('password', sau.PasswordType(), nullable=False), sa.Column('created_at', sa.DateTime(timezone=True), nullable=False), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email')) op.create_index(op.f('ix_tbl_users_created_at'), 'tbl_users', ['created_at'], unique=False) op.create_table( 'tbl_medical_records', sa.Column('mrid', sa.Unicode(128), nullable=False), sa.Column('ptnum', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['ptnum'], ['tbl_patients.ptnum'], ), sa.PrimaryKeyConstraint('mrid', 'ptnum')) op.create_index(op.f('ix_tbl_medical_records_ptnum'), 'tbl_medical_records', ['ptnum'], unique=False) op.create_table( 'tbl_positive_controls', sa.Column('id', sa.Integer(), nullable=False), sa.Column('note', sa.Unicode(128), nullable=False), sa.Column('lot_number', sa.Unicode(64), nullable=True), sa.Column('test_code', sa.Unicode(64), nullable=False), sa.Column('specimen_type', sa.Unicode(32), nullable=False), sa.Column('sequence_id', sa.Integer(), nullable=True), sa.Column('labnotes', sa.UnicodeText(), nullable=True), sa.Column('entered_at', sa.DateTime(timezone=True), nullable=False), sa.ForeignKeyConstraint( ['sequence_id'], ['tbl_sequences.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('sequence_id')) op.create_index(op.f('ix_tbl_positive_controls_entered_at'), 'tbl_positive_controls', ['entered_at'], unique=False) op.create_table( 'tbl_proficiency_samples', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.Unicode(128), nullable=False), sa.Column('source', sa.Unicode(64), nullable=False), sa.Column('vnum', sa.Unicode(64), nullable=False), sa.Column('test_code', sa.Unicode(64), nullable=False), sa.Column('sequence_id', sa.Integer(), nullable=True), sa.Column('notes', sa.UnicodeText(), nullable=True), sa.Column('labnotes', sa.UnicodeText(), nullable=True), sa.Column('received_at', sa.Date(), nullable=False), sa.Column('entered_at', sa.DateTime(timezone=True), nullable=False), sa.ForeignKeyConstraint( ['sequence_id'], ['tbl_sequences.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('sequence_id'), sa.UniqueConstraint('vnum', 'test_code', 'received_at')) op.create_index(op.f('ix_tbl_proficiency_samples_entered_at'), 'tbl_proficiency_samples', ['entered_at'], unique=False) op.create_index(op.f('ix_tbl_proficiency_samples_name'), 'tbl_proficiency_samples', ['name'], unique=False) op.create_index(op.f('ix_tbl_proficiency_samples_received_at'), 'tbl_proficiency_samples', ['received_at'], unique=False) op.create_index(op.f('ix_tbl_proficiency_samples_source'), 'tbl_proficiency_samples', ['source'], unique=False) op.create_index(op.f('ix_tbl_proficiency_samples_vnum'), 'tbl_proficiency_samples', ['vnum'], unique=False) op.create_table( 'tbl_patient_visits', sa.Column('id', sa.Integer(), nullable=False), sa.Column('ptnum', sa.Integer(), nullable=False), sa.Column('mrid', sa.Unicode(128), nullable=True), sa.Column('collected_at', sa.Date(), nullable=False), sa.ForeignKeyConstraint( ['mrid', 'ptnum'], ['tbl_medical_records.mrid', 'tbl_medical_records.ptnum'], ), sa.ForeignKeyConstraint( ['ptnum'], ['tbl_patients.ptnum'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('ptnum', 'collected_at')) op.create_index(op.f('ix_tbl_patient_visits_collected_at'), 'tbl_patient_visits', ['collected_at'], unique=False) op.create_table( 'tbl_positive_control_reports', sa.Column('positive_control_id', sa.Integer(), nullable=False), sa.Column('report_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['positive_control_id'], ['tbl_positive_controls.id'], ), sa.ForeignKeyConstraint( ['report_id'], ['tbl_reports.id'], ), sa.PrimaryKeyConstraint('positive_control_id', 'report_id')) op.create_table( 'tbl_proficiency_sample_reports', sa.Column('proficiency_sample_id', sa.Integer(), nullable=False), sa.Column('report_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['proficiency_sample_id'], ['tbl_proficiency_samples.id'], ), sa.ForeignKeyConstraint( ['report_id'], ['tbl_reports.id'], ), sa.PrimaryKeyConstraint('proficiency_sample_id', 'report_id')) op.create_table( 'tbl_patient_samples', sa.Column('id', sa.Integer(), nullable=False), sa.Column('vnum', sa.Unicode(64), nullable=False), sa.Column('test_code', sa.Unicode(64), nullable=False), sa.Column('specimen_type', sa.Unicode(32), nullable=False), sa.Column('patient_visit_id', sa.Integer(), nullable=False), sa.Column('sequence_id', sa.Integer(), nullable=True), sa.Column('physician_id', sa.Integer(), nullable=True), sa.Column('clinic_id', sa.Integer(), nullable=True), sa.Column('amplifiable', sa.Boolean(), nullable=True), sa.Column('notes', sa.UnicodeText(), nullable=True), sa.Column('labnotes', sa.UnicodeText(), nullable=True), sa.Column('received_at', sa.Date(), nullable=True), sa.Column('entered_at', sa.DateTime(timezone=True), nullable=False), sa.ForeignKeyConstraint( ['clinic_id'], ['tbl_clinics.id'], ), sa.ForeignKeyConstraint( ['patient_visit_id'], ['tbl_patient_visits.id'], ), sa.ForeignKeyConstraint( ['physician_id'], ['tbl_physicians.id'], ), sa.ForeignKeyConstraint( ['sequence_id'], ['tbl_sequences.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('sequence_id'), sa.UniqueConstraint('vnum', 'test_code', 'patient_visit_id')) op.create_index(op.f('ix_tbl_patient_samples_clinic_id'), 'tbl_patient_samples', ['clinic_id'], unique=False) op.create_index(op.f('ix_tbl_patient_samples_entered_at'), 'tbl_patient_samples', ['entered_at'], unique=False) op.create_index(op.f('ix_tbl_patient_samples_patient_visit_id'), 'tbl_patient_samples', ['patient_visit_id'], unique=False) op.create_index(op.f('ix_tbl_patient_samples_physician_id'), 'tbl_patient_samples', ['physician_id'], unique=False) op.create_index(op.f('ix_tbl_patient_samples_received_at'), 'tbl_patient_samples', ['received_at'], unique=False) op.create_index(op.f('ix_tbl_patient_samples_vnum'), 'tbl_patient_samples', ['vnum'], unique=False) op.create_table( 'tbl_patient_sample_reports', sa.Column('patient_sample_id', sa.Integer(), nullable=False), sa.Column('report_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['patient_sample_id'], ['tbl_patient_samples.id'], ), sa.ForeignKeyConstraint( ['report_id'], ['tbl_reports.id'], ), sa.PrimaryKeyConstraint('patient_sample_id', 'report_id'))