def upgrade(): op.create_table('role', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('created_at', sa.DateTime(), server_default=utcnow(), nullable=True), sa.Column('updated_at', sa.DateTime(), server_default=utcnow(), onupdate=utcnow(), nullable=True), sa.Column('name', sa.String(length=255), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name') )
def upgrade(): op.create_table('role_permission', sa.Column('created_at', sa.DateTime(), server_default=utcnow(), nullable=True), sa.Column('updated_at', sa.DateTime(), server_default=utcnow(), onupdate=utcnow(), nullable=True), sa.Column('role_id', sa.Integer(), nullable=True), sa.Column('permission_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint(['permission_id'], ['permission.id'], ondelete='CASCADE'), sa.ForeignKeyConstraint(['role_id'], ['role.id'], ondelete='CASCADE'), sa.PrimaryKeyConstraint('role_id', 'permission_id') )
class Transaction(Base): id = Column(UUIDType, primary_key=True, default=uuid.uuid4) created_at = Column(UtcDateTime, nullable=False, default=utcnow()) type = Column( EnumType(TransactionType, name='transaction_type'), nullable=False, index=True, ) user_id = Column( UUIDType, ForeignKey('user.id'), index=True, nullable=False, ) user = relationship('User') currency = Column( Unicode, ForeignKey('currency.id'), index=True, nullable=False, ) amount = Column(Numeric(36, 18), nullable=False) __tablename__ = 'transaction' __table_args__ = (CheckConstraint(amount != 0, 'ck_transaction_amount'), ) __mapper_args__ = { 'polymorphic_on': type, 'polymorphic_identity': None, 'with_polymorphic': '*', }
class User(Base, UserMixin): id = Column(UUIDType, primary_key=True, default=uuid.uuid4) created_at = Column(UtcDateTime, nullable=False, default=utcnow()) email = Column(EmailType, nullable=False, unique=True) password = Column(PasswordType(schemes=['pbkdf2_sha512']), nullable=False) __tablename__ = 'user' @typechecked def get_id(self) -> str: return str(self.id)
def upgrade(): op.create_table( 'thread_read', sa.Column('created_at', sa.DateTime(), server_default=utcnow(), nullable=True), sa.Column('updated_at', sa.DateTime(), server_default=utcnow(), onupdate=utcnow(), nullable=True), sa.Column('thread_id', sa.Integer(), nullable=False), sa.Column('user_id', sa.Integer(), nullable=False), sa.ForeignKeyConstraint( ['thread_id'], ['thread.id'], ), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('thread_id', 'user_id'))
def list(page): message_query = Message.query \ .filter(Message.thread_id == g.thread.id) \ .order_by(Message.created_at.asc()) \ .paginate(page, page_size, False) messages = message_query.items total = message_query.total if current_user.is_authenticated: thread_read = ThreadRead.query.get((g.thread.id, current_user.id)) if not thread_read: thread_read = ThreadRead(g.thread.id, current_user.id) db.session().add(thread_read) db.session().commit() thread_read.updated_at = utcnow() db.session().commit() form = DeleteMessageForm(request.form) return render_template('messages/list.html', messages=messages, total=total, page=page, form=form)
def upgrade(): op.create_table( 'topic', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('created_at', sa.DateTime(), server_default=utcnow(), nullable=True), sa.Column('updated_at', sa.DateTime(), server_default=utcnow(), onupdate=utcnow(), nullable=True), sa.Column('title', sa.String(length=255), nullable=True), sa.PrimaryKeyConstraint('id')) op.create_table( 'user', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('created_at', sa.DateTime(), server_default=utcnow(), nullable=True), sa.Column('updated_at', sa.DateTime(), server_default=utcnow(), onupdate=utcnow(), nullable=True), sa.Column('username', sa.String(length=255), nullable=True), sa.Column('password_hash', sa.String(length=255), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('username')) op.create_table( 'thread', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('created_at', sa.DateTime(), server_default=utcnow(), nullable=True), sa.Column('updated_at', sa.DateTime(), server_default=utcnow(), onupdate=utcnow(), nullable=True), sa.Column('title', sa.String(length=255), nullable=True), sa.Column('topic_id', sa.Integer(), nullable=True), sa.Column('user_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ['topic_id'], ['topic.id'], ), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id')) op.create_table( 'message', sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), sa.Column('created_at', sa.DateTime(), server_default=utcnow(), nullable=True), sa.Column('updated_at', sa.DateTime(), server_default=utcnow(), onupdate=utcnow(), nullable=True), sa.Column('text', sa.Text(), nullable=True), sa.Column('thread_id', sa.Integer(), nullable=True), sa.Column('user_id', sa.Integer(), nullable=True), sa.ForeignKeyConstraint( ['thread_id'], ['thread.id'], ), sa.ForeignKeyConstraint( ['user_id'], ['user.id'], ), sa.PrimaryKeyConstraint('id'))
class TimestampBase(db.Model): __abstract__ = True created_at = Column(DateTime, server_default=utcnow()) updated_at = Column(DateTime, server_default=utcnow(), onupdate=utcnow())