Skip to content

Commit 8b18885

Browse files
committed
added migrations for authentication
1 parent 3e5e7ce commit 8b18885

File tree

2 files changed

+67
-12
lines changed

2 files changed

+67
-12
lines changed

app/models.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
from flask_security import RoleMixin, UserMixin
66

77
language_identifier = db.Table('language_identifier',
8-
db.Column(
9-
'resource_id',
10-
db.Integer,
11-
db.ForeignKey('resource.id')),
12-
db.Column(
13-
'language_id',
14-
db.Integer,
15-
db.ForeignKey('language.id'))
16-
)
8+
db.Column(
9+
'resource_id',
10+
db.Integer,
11+
db.ForeignKey('resource.id')),
12+
db.Column(
13+
'language_id',
14+
db.Integer,
15+
db.ForeignKey('language.id'))
16+
)
1717

1818

1919
class TimestampMixin:
@@ -223,16 +223,19 @@ class Role(db.Model, RoleMixin):
223223
def __str__(self):
224224
return self.name
225225

226-
# __hash__ is required to avoid the exception TypeError: unhashable type: 'Role' when saving a User
226+
# __hash__ is required to avoid the exception
227+
# TypeError: unhashable type: 'Role' when saving a User
227228
def __hash__(self):
228229
return hash(self.name)
229230

230231

231232
# User class
232233
class User(db.Model, UserMixin):
233234

234-
# Our User has six fields: ID, email, password, active, confirmed_at and roles. The roles field represents a
235-
# many-to-many relationship using the roles_users table. Each user may have no role, one role, or multiple roles.
235+
# Our User has six fields: ID, email, password, active, confirmed_at
236+
# and roles. The roles field represents a many-to-many relationship
237+
# using the roles_users table. Each user may have no role, one role,
238+
# or multiple roles.
236239
id = db.Column(db.Integer, primary_key=True)
237240
email = db.Column(db.String(255), unique=True)
238241
password = db.Column(db.String(255))
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""empty message
2+
3+
Revision ID: 824f1576e904
4+
Revises: 205742d3b3f5
5+
Create Date: 2020-10-20 10:36:16.978231
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
import sqlalchemy_utils
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = '824f1576e904'
15+
down_revision = '205742d3b3f5'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.create_table('role',
23+
sa.Column('id', sa.Integer(), nullable=False),
24+
sa.Column('name', sa.String(length=80), nullable=True),
25+
sa.Column('description', sa.String(length=255), nullable=True),
26+
sa.PrimaryKeyConstraint('id'),
27+
sa.UniqueConstraint('name')
28+
)
29+
op.create_table('user',
30+
sa.Column('id', sa.Integer(), nullable=False),
31+
sa.Column('email', sa.String(length=255), nullable=True),
32+
sa.Column('password', sa.String(length=255), nullable=True),
33+
sa.Column('active', sa.Boolean(), nullable=True),
34+
sa.Column('confirmed_at', sa.DateTime(), nullable=True),
35+
sa.PrimaryKeyConstraint('id'),
36+
sa.UniqueConstraint('email')
37+
)
38+
op.create_table('roles_users',
39+
sa.Column('user_id', sa.Integer(), nullable=True),
40+
sa.Column('role_id', sa.Integer(), nullable=True),
41+
sa.ForeignKeyConstraint(['role_id'], ['role.id'], ),
42+
sa.ForeignKeyConstraint(['user_id'], ['user.id'], )
43+
)
44+
# ### end Alembic commands ###
45+
46+
47+
def downgrade():
48+
# ### commands auto generated by Alembic - please adjust! ###
49+
op.drop_table('roles_users')
50+
op.drop_table('user')
51+
op.drop_table('role')
52+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)