Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
csentry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Harrisson
csentry
Commits
2b3b5116
Commit
2b3b5116
authored
7 years ago
by
Benjamin Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Make sure to store timestamps in UTC
See
http://docs.sqlalchemy.org/en/latest/core/compiler.html#utc-timestamp-function
parent
95814aa2
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/models.py
+13
-3
13 additions, 3 deletions
app/models.py
with
13 additions
and
3 deletions
app/models.py
+
13
−
3
View file @
2b3b5116
...
@@ -31,6 +31,16 @@ HOST_NAME_RE = re.compile('^[a-z0-9\-]{2,20}$')
...
@@ -31,6 +31,16 @@ HOST_NAME_RE = re.compile('^[a-z0-9\-]{2,20}$')
make_versioned
(
plugins
=
[
FlaskUserPlugin
()])
make_versioned
(
plugins
=
[
FlaskUserPlugin
()])
# See http://docs.sqlalchemy.org/en/latest/core/compiler.html#utc-timestamp-function
class
utcnow
(
sa
.
sql
.
expression
.
FunctionElement
):
type
=
sa
.
types
.
DateTime
()
@sa.ext.compiler.compiles
(
utcnow
,
'
postgresql
'
)
def
pg_utcnow
(
element
,
compiler
,
**
kw
):
return
"
TIMEZONE(
'
utc
'
, CURRENT_TIMESTAMP)
"
@login_manager.user_loader
@login_manager.user_loader
def
load_user
(
user_id
):
def
load_user
(
user_id
):
"""
User loader callback for flask-login
"""
User loader callback for flask-login
...
@@ -220,8 +230,8 @@ class Item(db.Model):
...
@@ -220,8 +230,8 @@ class Item(db.Model):
}
}
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
_created
=
db
.
Column
(
db
.
DateTime
,
default
=
db
.
func
.
now
())
_created
=
db
.
Column
(
db
.
DateTime
,
default
=
utc
now
())
_updated
=
db
.
Column
(
db
.
DateTime
,
default
=
db
.
func
.
now
(),
onupdate
=
db
.
func
.
now
())
_updated
=
db
.
Column
(
db
.
DateTime
,
default
=
utc
now
(),
onupdate
=
utc
now
())
ics_id
=
db
.
Column
(
db
.
Text
,
unique
=
True
,
index
=
True
)
ics_id
=
db
.
Column
(
db
.
Text
,
unique
=
True
,
index
=
True
)
serial_number
=
db
.
Column
(
db
.
Text
,
nullable
=
False
)
serial_number
=
db
.
Column
(
db
.
Text
,
nullable
=
False
)
manufacturer_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'
manufacturer.id
'
))
manufacturer_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'
manufacturer.id
'
))
...
@@ -301,7 +311,7 @@ class Item(db.Model):
...
@@ -301,7 +311,7 @@ class Item(db.Model):
class
ItemComment
(
db
.
Model
):
class
ItemComment
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
timestamp
=
db
.
Column
(
db
.
DateTime
,
default
=
db
.
func
.
now
(),
index
=
True
)
timestamp
=
db
.
Column
(
db
.
DateTime
,
default
=
utc
now
(),
index
=
True
)
text
=
db
.
Column
(
db
.
Text
,
nullable
=
False
)
text
=
db
.
Column
(
db
.
Text
,
nullable
=
False
)
user_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'
user_account.id
'
),
nullable
=
False
)
user_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'
user_account.id
'
),
nullable
=
False
)
item_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'
item.id
'
),
nullable
=
False
)
item_id
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'
item.id
'
),
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