Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
elp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
崔为之
elp
Commits
47258f4c
Commit
47258f4c
authored
Nov 12, 2023
by
崔为之
💪🏽
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update project
parent
8dbea5c1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
16 deletions
+10
-16
application/config/config.yaml
application/config/config.yaml
+2
-9
application/extensions/init_sqlalchemy.py
application/extensions/init_sqlalchemy.py
+2
-2
application/libs/tasks/task.py
application/libs/tasks/task.py
+2
-0
application/models/user.py
application/models/user.py
+4
-5
No files found.
application/config/config.yaml
View file @
47258f4c
...
...
@@ -9,7 +9,7 @@ Database:
Host
:
localhost
Port
:
5432
DB
:
elp
TableName
:
user
TableName
:
user
s
Elasticsearch
:
Host
:
172.28.5.39
...
...
@@ -32,14 +32,7 @@ Logger:
Enqueue
:
True
Retention
:
Redis
:
Host
:
localhost
Port
:
6379
Username
:
Password
:
DB
:
13
Scheduler
:
Start
:
2023-11-1
1 18:20
:00
Start
:
2023-11-1
2 10:04
:00
End
:
2099-11-11 16:00:00
Timezone
:
Asia/Shanghai
application/extensions/init_sqlalchemy.py
View file @
47258f4c
...
...
@@ -40,8 +40,8 @@ def init_database(app: Flask) -> None:
db
.
app
=
app
db
.
init_app
(
app
)
with
app
.
app_context
():
db
.
session
.
execute
(
text
(
"""
CREATE TABLE IF NOT EXISTS
users
(
db
.
session
.
execute
(
text
(
f
"""
CREATE TABLE IF NOT EXISTS
{
cfg
.
TableName
}
(
id SERIAL NOT NULL,
username VARCHAR(80) NOT NULL,
email VARCHAR(120) NOT NULL,
...
...
application/libs/tasks/task.py
View file @
47258f4c
...
...
@@ -13,6 +13,7 @@
import
datetime
from
application.extensions.init_sqlalchemy
import
db
from
application.models
import
User
from
application.common
import
global_config
def
task
():
...
...
@@ -26,4 +27,5 @@ def task():
user
=
User
(
username
=
"CWzz"
,
email
=
"Stuu@outlook.com"
,
password
=
"qwe!2345"
,
active
=
True
,
created_at
=
datetime
.
datetime
.
utcnow
())
user
.
save
()
print
(
db
.
app
.
config
)
print
(
"created user admin"
)
application/models/user.py
View file @
47258f4c
...
...
@@ -10,7 +10,7 @@
# @Description :
"""
from
datetime
import
datetime
import
os
from
sqlalchemy
import
text
from
sqlalchemy.ext.hybrid
import
hybrid_property
...
...
@@ -20,7 +20,7 @@ from application.extensions.init_sqlalchemy import db
class
User
(
db
.
Model
):
"""Basic user model"""
__tablename__
=
'users'
__tablename__
=
os
.
environ
.
get
(
'TableName'
,
'users'
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
username
=
db
.
Column
(
db
.
String
(
80
),
unique
=
True
,
nullable
=
False
)
...
...
@@ -54,14 +54,13 @@ class User(db.Model):
def
save
(
self
):
partition_date
=
self
.
created_at
.
strftime
(
'%Y_%m'
)
partition_name
=
f
'
users
_
{
partition_date
}
'
partition_name
=
f
'
{
self
.
__tablename__
}
_
{
partition_date
}
'
with
db
.
session
.
begin_nested
():
db
.
session
.
execute
(
text
(
f
"""
CREATE TABLE IF NOT EXISTS
{
partition_name
}
PARTITION OF
users
CREATE TABLE IF NOT EXISTS
{
partition_name
}
PARTITION OF
{
self
.
__tablename__
}
FOR VALUES FROM ('
{
self
.
created_at
.
strftime
(
'%Y-%m-01'
)
}
') TO
('
{
self
.
created_at
.
strftime
(
'%Y-%m-01'
)
}
'::date + interval '1 month');
"""
))
db
.
session
.
add
(
self
)
db
.
session
.
commit
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment