Skip to content

Commit

Permalink
Closes frol#51: problem install with PostgreSQL database
Browse files Browse the repository at this point in the history
Add PostgreSQL parameters to config (comment them by default)

Update the existed migrations to make them work with PostgreSQL.
  • Loading branch information
khorolets committed Mar 7, 2017
1 parent 8e08e70 commit 19a7b4a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
15 changes: 15 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ class BaseConfig(object):

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))

# POSTGRESQL
# DB_USER = 'user'
# DB_PASSWORD = 'password'
# DB_NAME = 'restplusdb'
# DB_HOST = 'localhost'
# DB_PORT = 5432
# SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{password}@{host}:{port}/{name}'.format(
# user=DB_USER,
# password=DB_PASSWORD,
# host=DB_HOST,
# post=DB_PORT,
# name=DB_NAME,
# )

# SQLITE
SQLALCHEMY_DATABASE_URI = 'sqlite:///%s' % (os.path.join(PROJECT_ROOT, "example.db"))

DEBUG = False
Expand Down
3 changes: 2 additions & 1 deletion migrations/versions/36954739c63_.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def upgrade():
batch_op.alter_column('password',
existing_type=sa.VARCHAR(length=128),
type_=sqlalchemy_utils.types.password.PasswordType(max_length=128),
existing_nullable=False)
existing_nullable=False,
postgresql_using='password::bytea')
### end Alembic commands ###

user = sa.Table('user',
Expand Down
8 changes: 7 additions & 1 deletion migrations/versions/5e2954a2af18_refactored-auth-oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@
def upgrade():
connection = op.get_bind()

clienttypes = sa.dialects.postgresql.ENUM('public', 'confidential', name='clienttypes')
clienttypes.create(connection)

with op.batch_alter_table('oauth2_client') as batch_op:
batch_op.add_column(
sa.Column(
'client_type',
sa.Enum('public', 'confidential'),
sa.Enum('public', 'confidential', name='clienttypes'),
server_default='public',
nullable=False
)
Expand Down Expand Up @@ -168,6 +171,9 @@ def downgrade():
OAuth2Client.update().values(_redirect_uris=OAuth2Client.c.redirect_uris)
)

clienttypes = sa.dialects.postgresql.ENUM('public', 'confidential', name='clienttypes')
clienttypes.drop(connection)

with op.batch_alter_table('oauth2_client') as batch_op:
batch_op.drop_column('redirect_uris')
batch_op.drop_column('default_scopes')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,28 @@


def upgrade():
connection = op.get_bind()


with op.batch_alter_table('oauth2_token') as batch_op:
tokentypes = sa.dialects.postgresql.ENUM('Bearer', name='tokentypes')
tokentypes.create(connection)

batch_op.alter_column('token_type',
existing_type=sa.VARCHAR(length=40),
type_=sa.Enum('Bearer', name='tokentypes'),
existing_nullable=False)
existing_nullable=False,
postgresql_using='token_type::tokentypes')


def downgrade():
connection = op.get_bind()

with op.batch_alter_table('oauth2_token') as batch_op:
batch_op.alter_column('token_type',
existing_type=sa.Enum('Bearer', name='tokentypes'),
type_=sa.VARCHAR(length=40),
existing_nullable=False)

tokentypes = sa.dialects.postgresql.ENUM('Bearer', name='tokentypes')
tokentypes.drop(connection)

0 comments on commit 19a7b4a

Please sign in to comment.