def upgrade():
    """Upgrade database."""
    op.create_table(
        'oauth2server_client',
        sa.Column('name', sa.String(length=40), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('website',
                  sqlalchemy_utils.types.url.URLType(),
                  nullable=True),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('client_id', sa.String(length=255), nullable=False),
        sa.Column('client_secret', sa.String(length=255), nullable=False),
        sa.Column('is_confidential',
                  sa.Boolean(name='is_confidential'),
                  nullable=True),
        sa.Column('is_internal', sa.Boolean(name='is_internal'),
                  nullable=True),
        sa.Column('_redirect_uris', sa.Text(), nullable=True),
        sa.Column('_default_scopes', sa.Text(), nullable=True),
        sa.ForeignKeyConstraint(
            ['user_id'],
            [u'accounts_user.id'],
        ), sa.PrimaryKeyConstraint('client_id'))
    op.create_index(op.f('ix_oauth2server_client_client_secret'),
                    'oauth2server_client', ['client_secret'],
                    unique=True)
    op.create_table(
        'oauth2server_token', sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('client_id', sa.String(length=255), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=True),
        sa.Column('token_type', sa.String(length=255), nullable=True),
        sa.Column('access_token',
                  sqlalchemy_utils.EncryptedType(),
                  nullable=True),
        sa.Column('refresh_token',
                  sqlalchemy_utils.EncryptedType(),
                  nullable=True),
        sa.Column('expires', sa.DateTime(), nullable=True),
        sa.Column('_scopes', sa.Text(), nullable=True),
        sa.Column('is_personal', sa.Boolean(name='is_personal'),
                  nullable=True),
        sa.Column('is_internal', sa.Boolean(name='is_internal'),
                  nullable=True),
        sa.ForeignKeyConstraint(
            ['client_id'],
            [u'oauth2server_client.client_id'],
        ), sa.ForeignKeyConstraint(
            ['user_id'],
            [u'accounts_user.id'],
        ), sa.PrimaryKeyConstraint('id'))
    op.create_index('ix_oauth2server_token_access_token',
                    'oauth2server_token', ['access_token'],
                    unique=True,
                    mysql_length=255)
    op.create_index('ix_oauth2server_token_refresh_token',
                    'oauth2server_token', ['refresh_token'],
                    unique=True,
                    mysql_length=255)
Esempio n. 2
0
class User(db.Model, UserMixin):
    """Model representing a user."""

    __tablename__ = "users"
    id = db.Column("id", db.Integer(), primary_key=True, autoincrement=True)
    email = db.Column("email", db.String(), unique=True)
    name = db.Column("name", db.String(length=40))
    ew_key = db.Column(
        "ew_key",
        sqlalchemy_utils.EncryptedType(db.String(50),
                                       application.config["SECRET_KEY"],
                                       FernetEngine),
    )
    password = db.Column("password", db.String())
class Karma(Base):
    __tablename__ = "karma"

    id = sa.Column(sa.Integer, primary_key=True, nullable=False)
    name = sa.Column(sa.String, nullable=False)
    added = sa.Column(
        sau.EncryptedType(type_in=sa.DateTime, key=secret_key),
        nullable=False,
        default=sa.func.current_timestamp(),
    )
    added_new = sa.Column(
        sa.DateTime,
        nullable=False,
        default=sa.func.current_timestamp(),
    )
    pluses = sa.Column(sa.Integer, nullable=False, default=0)
    minuses = sa.Column(sa.Integer, nullable=False, default=0)
    neutrals = sa.Column(sa.Integer, nullable=False, default=0)
Esempio n. 4
0
class KarmaChange(Base):
    __tablename__ = "karma_changes"

    karma_id = sa.Column(sa.Integer,
                         sa.ForeignKey("karma.id"),
                         primary_key=True,
                         nullable=False)
    user_id = sa.Column(sa.Integer,
                        sa.ForeignKey("users.id"),
                        primary_key=True,
                        nullable=False)
    message_id = sa.Column(sa.Integer,
                           sa.ForeignKey("messages.id"),
                           primary_key=True,
                           nullable=False)
    created_at = sa.Column(sa.DateTime, nullable=False)
    reasons = sa.Column(
        sau.EncryptedType(type_in=sau.ScalarListType(str), key=secret_key),
        nullable=True,
    )
    reason = sa.Column(sa.String(1024), nullable=True)
Esempio n. 5
0
class KarmaChange(Base):
    __tablename__ = "karma_changes"

    karma_id = sa.Column(sa.Integer,
                         sa.ForeignKey("karma.id"),
                         primary_key=True,
                         nullable=False)
    user_id = sa.Column(sa.Integer,
                        sa.ForeignKey("users.id"),
                        primary_key=True,
                        nullable=False)
    message_id = sa.Column(sa.Integer,
                           sa.ForeignKey("messages.id"),
                           primary_key=True,
                           nullable=False)
    created_at = sa.Column(sa.DateTime, nullable=False)
    # Using a Greek question mark (;) instead of a semicolon here!
    reasons = sa.Column(
        sau.EncryptedType(type_in=sau.ScalarListType(str), key=secret_key),
        nullable=True,
    )
    reasons_new = sa.Column(sau.ScalarListType(str, separator=";"),
                            nullable=True)
def upgrade():
    """Upgrade database."""
    op.create_table(
        'oauthclient_remoteaccount',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('user_id', sa.Integer(), nullable=False),
        sa.Column('client_id', sa.String(length=255), nullable=False),
        sa.Column('extra_data', sqlalchemy_utils.JSONType(), nullable=False),
        sa.ForeignKeyConstraint(
            ['user_id'],
            [u'accounts_user.id'],
        ), sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('user_id', 'client_id'))
    op.create_table(
        'oauthclient_useridentity',
        sa.Column('id', sa.String(length=255), nullable=False),
        sa.Column('method', sa.String(length=255), nullable=False),
        sa.Column('id_user', sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ['id_user'],
            [u'accounts_user.id'],
        ), sa.PrimaryKeyConstraint('id', 'method'))
    op.create_index('useridentity_id_user_method',
                    'oauthclient_useridentity', ['id_user', 'method'],
                    unique=True)
    op.create_table(
        'oauthclient_remotetoken',
        sa.Column('id_remote_account', sa.Integer(), nullable=False),
        sa.Column('token_type', sa.String(length=40), nullable=False),
        sa.Column('access_token',
                  sqlalchemy_utils.EncryptedType(),
                  nullable=False),
        sa.Column('secret', sa.Text(), nullable=False),
        sa.ForeignKeyConstraint(
            ['id_remote_account'], [u'oauthclient_remoteaccount.id'],
            name='fk_oauthclient_remote_token_remote_account'),
        sa.PrimaryKeyConstraint('id_remote_account', 'token_type'))