Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Hiboo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cyrinux
Hiboo
Commits
bd54344d
Commit
bd54344d
authored
5 years ago
by
kaiyou
Browse files
Options
Downloads
Patches
Plain Diff
Update the database models
parent
01069bc5
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
migrations/script.py.mako
+1
-3
1 addition, 3 deletions
migrations/script.py.mako
migrations/versions/a95b3a78f983_.py
+68
-0
68 additions, 0 deletions
migrations/versions/a95b3a78f983_.py
trurt/models.py
+46
-32
46 additions, 32 deletions
trurt/models.py
with
115 additions
and
35 deletions
migrations/script.py.mako
+
1
−
3
View file @
bd54344d
"""${message}
"""
${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
...
...
This diff is collapsed.
Click to expand it.
migrations/versions/a95b3a78f983_.py
0 → 100644
+
68
−
0
View file @
bd54344d
"""
Create initial schemas
Revision ID: a95b3a78f983
Revises:
Create Date: 2019-09-10 21:33:43.332000
"""
from
alembic
import
op
import
sqlalchemy
as
sa
revision
=
'
a95b3a78f983
'
down_revision
=
None
branch_labels
=
None
depends_on
=
None
def
upgrade
():
op
.
create_table
(
'
service
'
,
sa
.
Column
(
'
spn
'
,
sa
.
String
(
length
=
255
),
nullable
=
True
),
sa
.
Column
(
'
protocol
'
,
sa
.
String
(
length
=
25
),
nullable
=
True
),
sa
.
Column
(
'
config
'
,
sa
.
String
(),
nullable
=
True
),
sa
.
Column
(
'
id
'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
Date
(),
nullable
=
False
),
sa
.
Column
(
'
updated_at
'
,
sa
.
Date
(),
nullable
=
True
),
sa
.
Column
(
'
comment
'
,
sa
.
String
(
length
=
255
),
nullable
=
True
),
sa
.
PrimaryKeyConstraint
(
'
id
'
),
sa
.
UniqueConstraint
(
'
spn
'
)
)
op
.
create_table
(
'
user
'
,
sa
.
Column
(
'
username
'
,
sa
.
String
(
length
=
255
),
nullable
=
False
),
sa
.
Column
(
'
id
'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
Date
(),
nullable
=
False
),
sa
.
Column
(
'
updated_at
'
,
sa
.
Date
(),
nullable
=
True
),
sa
.
Column
(
'
comment
'
,
sa
.
String
(
length
=
255
),
nullable
=
True
),
sa
.
PrimaryKeyConstraint
(
'
id
'
),
sa
.
UniqueConstraint
(
'
username
'
)
)
op
.
create_table
(
'
auth
'
,
sa
.
Column
(
'
user_id
'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'
value
'
,
sa
.
String
(),
nullable
=
True
),
sa
.
Column
(
'
extra
'
,
sa
.
String
(),
nullable
=
True
),
sa
.
Column
(
'
id
'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
Date
(),
nullable
=
False
),
sa
.
Column
(
'
updated_at
'
,
sa
.
Date
(),
nullable
=
True
),
sa
.
Column
(
'
comment
'
,
sa
.
String
(
length
=
255
),
nullable
=
True
),
sa
.
ForeignKeyConstraint
([
'
user_id
'
],
[
'
user.id
'
],
),
sa
.
PrimaryKeyConstraint
(
'
id
'
)
)
op
.
create_table
(
'
profile
'
,
sa
.
Column
(
'
user_id
'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'
service_id
'
,
sa
.
Integer
(),
nullable
=
True
),
sa
.
Column
(
'
username
'
,
sa
.
String
(
length
=
255
),
nullable
=
False
),
sa
.
Column
(
'
id
'
,
sa
.
Integer
(),
nullable
=
False
),
sa
.
Column
(
'
created_at
'
,
sa
.
Date
(),
nullable
=
False
),
sa
.
Column
(
'
updated_at
'
,
sa
.
Date
(),
nullable
=
True
),
sa
.
Column
(
'
comment
'
,
sa
.
String
(
length
=
255
),
nullable
=
True
),
sa
.
ForeignKeyConstraint
([
'
service_id
'
],
[
'
service.id
'
],
),
sa
.
ForeignKeyConstraint
([
'
user_id
'
],
[
'
user.id
'
],
),
sa
.
PrimaryKeyConstraint
(
'
id
'
)
)
def
downgrade
():
op
.
drop_table
(
'
profile
'
)
op
.
drop_table
(
'
auth
'
)
op
.
drop_table
(
'
user
'
)
op
.
drop_table
(
'
service
'
)
This diff is collapsed.
Click to expand it.
trurt/models.py
+
46
−
32
View file @
bd54344d
from
sqlalchemy.ext
import
declarative
from
passlib
import
context
,
hash
from
datetime
import
datetime
,
date
from
flask
import
current_app
as
app
from
sqlalchemy.ext
import
declarative
from
datetime
import
date
import
flask_sqlalchemy
import
sqlalchemy
import
time
import
os
import
glob
db
=
flask_sqlalchemy
.
SQLAlchemy
()
class
Base
(
flask_sqlalchemy
.
Model
):
"""
Base class for all models
"""
metadata
=
sqlalchemy
.
schema
.
MetaData
(
naming_convention
=
{
"
fk
"
:
"
%(table_name)s_%(column_0_name)s_fkey
"
,
"
pk
"
:
"
%(table_name)s_pkey
"
}
)
@declarative.declared_attr
def
id
(
cls
):
return
sqlalchemy
.
Column
(
sqlalchemy
.
Integer
(),
primary_key
=
True
)
@declarative.declared_attr
def
created_at
(
cls
):
return
sqlalchemy
.
Column
(
sqlalchemy
.
Date
,
nullable
=
False
,
default
=
date
.
today
)
@declarative.declared_attr
def
updated_at
(
cls
):
return
sqlalchemy
.
Column
(
sqlalchemy
.
Date
,
nullable
=
True
,
onupdate
=
date
.
today
)
@declarative.declared_attr
def
comment
(
cls
):
return
sqlalchemy
.
Column
(
sqlalchemy
.
String
(
255
),
nullable
=
True
)
db
=
flask_sqlalchemy
.
SQLAlchemy
(
model_class
=
Base
)
class
JSONEncoded
(
db
.
TypeDecorator
):
...
...
@@ -26,38 +50,19 @@ class JSONEncoded(db.TypeDecorator):
return
json
.
loads
(
value
)
if
value
else
None
class
Base
(
db
.
Model
):
"""
Base class for all models
"""
__abstract__
=
True
metadata
=
sqlalchemy
.
schema
.
MetaData
(
naming_convention
=
{
"
fk
"
:
"
%(table_name)s_%(column_0_name)s_fkey
"
,
"
pk
"
:
"
%(table_name)s_pkey
"
}
)
id
=
db
.
Column
(
db
.
Integer
(),
primary_key
=
True
)
created_at
=
db
.
Column
(
db
.
Date
,
nullable
=
False
,
default
=
date
.
today
)
updated_at
=
db
.
Column
(
db
.
Date
,
nullable
=
True
,
onupdate
=
date
.
today
)
comment
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
True
)
class
User
(
Base
):
class
User
(
db
.
Model
):
"""
A user is the local representation of an authenticated person.
"""
__tablename__
=
"
user
"
username
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
,
unique
=
True
)
# Flask-login attributes
is_authenticated
=
True
is_active
=
True
is_anonymous
=
False
@classmethod
def
get
(
cls
,
id
):
return
cls
.
query
.
get
(
id
)
...
...
@@ -65,12 +70,12 @@ class User(Base):
return
self
.
id
class
Auth
(
Base
):
class
Auth
(
db
.
Model
):
"""
An authenticator is a method to authenticate a user.
"""
__tablename__
=
"
auth
"
user_
username
=
db
.
Column
(
db
.
Integer
(),
db
.
ForeignKey
(
User
.
id
))
user_
id
=
db
.
Column
(
db
.
Integer
(),
db
.
ForeignKey
(
User
.
id
))
user
=
db
.
relationship
(
User
,
backref
=
db
.
backref
(
'
auths
'
,
cascade
=
'
all, delete-orphan
'
))
# TODO: support multiple authentication realms, therefore more than
...
...
@@ -78,8 +83,14 @@ class Auth(Base):
value
=
db
.
Column
(
db
.
String
)
extra
=
db
.
Column
(
JSONEncoded
)
def
set_password
(
self
,
password
):
self
.
value
=
hash
.
pbkdf2_sha256
.
hash
(
password
)
def
check_password
(
self
,
password
):
return
hash
.
pbkdf2_sha256
.
verify
(
password
,
self
.
password
)
class
Service
(
Base
):
class
Service
(
db
.
Model
):
"""
A service is a client application (SP or RP typically).
"""
__tablename__
=
"
service
"
...
...
@@ -89,13 +100,16 @@ class Service(Base):
config
=
db
.
Column
(
JSONEncoded
)
class
Profile
(
Base
):
class
Profile
(
db
.
Model
):
"""
A profile is a user instance for a given service.
"""
__tablename__
=
"
profile
"
username
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
user_id
=
db
.
Column
(
db
.
Integer
(),
db
.
ForeignKey
(
User
.
id
))
service_id
=
db
.
Column
(
db
.
Integer
(),
db
.
ForeignKey
(
Service
.
id
))
user
=
db
.
relationship
(
User
,
backref
=
db
.
backref
(
'
profiles
'
,
cascade
=
'
all, delete-orphan
'
))
service
=
db
.
relationship
(
Service
,
backref
=
db
.
backref
(
'
profiles
'
,
cascade
=
'
all, delete-orphan
'
))
username
=
db
.
Column
(
db
.
String
(
255
),
nullable
=
False
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment