class Transaction(db.Model): """ Tippic transactions: from and to the server """ tx_hash = db.Column(db.String(100), nullable=False, primary_key=True) user_id = db.Column('user_id', UUIDType(binary=False), db.ForeignKey("user.user_id"), primary_key=False, nullable=False) to_address = db.Column(db.String(60), primary_key=False, unique=False, nullable=False) amount = db.Column(db.Integer(), nullable=False, primary_key=False) tx_for_item_id = db.Column(db.String(100), nullable=False, primary_key=False) tx_type = db.Column(db.String(20), primary_key=False, unique=False, nullable=False) update_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now(), onupdate=db.func.now()) def __repr__(self): return '<tx_hash: %s, type: %s, user_id: %s, amount: %s, to_address: %s, tx_for_item_id: %s, update_at: %s>' % \ (self.tx_hash, self.tx_type, self.user_id, self.amount, self.to_address, self.tx_for_item_id, self.update_at)
class P2PTransaction(db.Model): """ p2p transactions: between users """ sender_user_id = db.Column('sender_user_id', UUIDType(binary=False), db.ForeignKey("user.user_id"), unique=False, nullable=False) receiver_user_id = db.Column('receiver_user_id', UUIDType(binary=False), db.ForeignKey("user.user_id"), unique=False, nullable=False) tx_hash = db.Column(db.String(100), nullable=False, primary_key=True) amount = db.Column(db.Integer(), nullable=False, primary_key=False) sender_address = db.Column(db.String(60), db.ForeignKey("user.public_address"), nullable=False, unique=False) receiver_address = db.Column(db.String(60), db.ForeignKey("user.public_address"), nullable=False, unique=False) update_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now(), onupdate=db.func.now()) def __repr__(self): return '<p2ptx_hash: %s, sender_user_id: %s, receiver_user_id: %s, ' \ 'amount: %s, sender_address: %s, receiver_address: %s, update_at: %s>' % (self.tx_hash, self.sender_user_id, self.receiver_user_id, self.amount, self.sender_address, self.receiver_address, self.update_at)
class SystemConfig(db.Model): """SytemConfig is a table with various configuration options that are coded into the db""" sid = db.Column(db.Integer(), db.Sequence('sid', start=1, increment=1), primary_key=True) block_clients_below_version_android = db.Column( 'block_clients_below_version_android', db.String(100), nullable=True, primary_key=False) block_clients_below_version_ios = db.Column( 'block_clients_below_version_ios', db.String(100), nullable=True, primary_key=False) update_available_below_version_android = db.Column( 'update_available_below_version_android', db.String(100), nullable=True, primary_key=False) update_available_below_version_ios = db.Column( 'update_available_below_version_ios', db.String(100), nullable=True, primary_key=False) categories_extra_data = db.Column( db.JSON) # all sorts of extra global data pertaining to categories current_picture_index = db.Column(db.Integer(), nullable=True, primary_key=False)
class EmailTemplate(db.Model): """email templates for various uses""" template_type = db.Column(db.String(100), primary_key=True) title = db.Column(db.String(200), primary_key=False) body = db.Column(db.String(100000), primary_key=False) sent_from = db.Column(db.String(100), primary_key=False) def __repr__(self): return '<template_type: %s, title: %s, body: %s, sent_from: %s>' % ( self.template_type, self.title, self.body, self.sent_from)
class Picture(db.Model): """ the represents a single picture """ picture_id = db.Column(db.String(40), nullable=False, primary_key=True) picture_order_index = db.Column(db.Integer(), nullable=False, primary_key=False) title = db.Column(db.String(80), nullable=False, primary_key=False) image_url = db.Column(db.String(200), nullable=False, primary_key=False) author = db.Column(db.JSON) update_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now(), onupdate=db.func.now()) is_active = db.Column(db.Boolean, unique=False, default=True) def __repr__(self): return '<picture_id: %s, ' \ 'picture_order_index: %s,' \ 'title: %s,' \ 'author: %s, ' \ 'image_url: %s>' % (self.picture_id, self.picture_order_index, self.title, self.author, self.image_url)
class BackupQuestion(db.Model): """the BackupQuestion model represents a single backup question. these are essentially hardcoded into the db. """ sid = db.Column(db.Integer(), db.Sequence('sid', start=1, increment=1), primary_key=True) question_text = db.Column('question_text', db.String(300), unique=True) updated_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now(), onupdate=db.func.now()) def __repr__(self): return '<sid: %s, question_text: %s' \ ' updated_at: %s>' % (self.sid, self.question_text, self.updated_at)
class PhoneBackupHints(db.Model): """the PhoneBackupHints model holds (for each userid) the sid of the questions selected by the user for the recent-most backup. """ enc_phone_number = db.Column('enc_phone_number', db.String(200), primary_key=True, nullable=False) # cant be a foreign key because its not unique in user. hints = db.Column(db.JSON(), nullable=False) updated_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now(), onupdate=db.func.now()) previous_hints = db.Column(db.JSON(), nullable=True) def __repr__(self): return '<user_id: %s, hints: %s' \ ' updated_at: %s>' % (self.enc_phone_number, self.hints, self.updated_at)
class BlacklistedEncPhoneNumber(db.Model): """the PhoneBackupHints model holds (for each userid) the sid of the questions selected by the user for the recent-most backup. """ enc_phone_number = db.Column( 'enc_phone_number', db.String(200), primary_key=True, nullable=False ) # cant be a foreign key because its not unique in user. added_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) def __repr__(self): return '<enc_phone_number: %s, added_at: %s>' % (self.enc_phone_number, self.added_at)
class UserAppData(db.Model): """ the user app data model tracks the version of the app installed @ the client """ user_id = db.Column('user_id', UUIDType(binary=False), db.ForeignKey("user.user_id"), primary_key=True, nullable=False) app_ver = db.Column(db.String(40), primary_key=False, nullable=False) update_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now(), onupdate=db.func.now()) ip_address = db.Column(INET) # the user's last known ip country_iso_code = db.Column( db.String(10)) # country iso code based on last ip captcha_history = db.Column(db.JSON) blocked_users = db.Column(db.JSON) should_solve_captcha_ternary = db.Column( db.Integer, unique=False, default=0, nullable=False ) # -1 = no captcha, 0 = show captcha on next task, 1 = captcha required
class User(db.Model): """ the user model """ sid = db.Column(db.Integer(), db.Sequence('sid', start=1, increment=1), primary_key=False) user_id = db.Column(UUIDType(binary=False), primary_key=True, nullable=False) username = db.Column(db.String(40), primary_key=False, nullable=True) os_type = db.Column(db.String(10), primary_key=False, nullable=False) device_model = db.Column(db.String(DEVICE_MODEL_MAX_SIZE), primary_key=False, nullable=False) push_token = db.Column(db.String(200), primary_key=False, nullable=True) time_zone = db.Column(db.Integer(), primary_key=False, nullable=False) device_id = db.Column(db.String(40), primary_key=False, nullable=True) created_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now()) onboarded = db.Column(db.Boolean, unique=False, default=False) public_address = db.Column(db.String(60), primary_key=False, unique=True, nullable=True) enc_phone_number = db.Column(db.String(200), primary_key=False, nullable=True) deactivated = db.Column(db.Boolean, unique=False, default=False) auth_token = db.Column(UUIDType(binary=False), primary_key=False, nullable=True) package_id = db.Column(db.String(60), primary_key=False, nullable=True) def __repr__(self): return '<sid: %s, user_id: %s, os_type: %s, device_model: %s, push_token: %s, time_zone: %s, device_id: %s,' \ ' onboarded: %s, public_address: %s, enc_phone_number: %s, package_id: %s, deactivated: %s'\ % (self.sid, self.user_id, self.os_type, self.device_model, self.push_token, self.time_zone, self.device_id, self.onboarded, self.public_address, self.enc_phone_number, self.package_id, self.deactivated)
class ReportedPictures(db.Model): picture_id = db.Column(db.String(40), nullable=False, primary_key=True) reporter_id = db.Column('user_id', UUIDType(binary=False), db.ForeignKey("user.user_id"), primary_key=True, nullable=False) update_at = db.Column(db.DateTime(timezone=True), server_default=db.func.now(), onupdate=db.func.now())