Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rabbitmq_agents
Manage
Activity
Members
Labels
Plan
Issues
13
Issue boards
Milestones
Wiki
Code
Merge requests
8
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
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
rc
rabbitmq_agents
Merge requests
!150
Draft: Add created column
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Draft: Add created column
louistw/rabbitmq_agents:feat-created-column
into
main
Overview
0
Commits
12
Pipelines
5
Changes
4
Open
Bo-Chun Chen
requested to merge
louistw/rabbitmq_agents:feat-created-column
into
main
11 months ago
Overview
0
Commits
12
Pipelines
5
Changes
1
Expand
Closes
#152
👍
0
👎
0
Merge request reports
Compare
version 4
version 4
9db42a2d
11 months ago
version 3
16c77ef7
11 months ago
version 2
55845a2a
11 months ago
version 1
e9c7658b
11 months ago
main (HEAD)
and
latest version
latest version
8600358a
12 commits,
10 months ago
version 4
9db42a2d
5 commits,
11 months ago
version 3
16c77ef7
4 commits,
11 months ago
version 2
55845a2a
3 commits,
11 months ago
version 1
e9c7658b
1 commit,
11 months ago
Show latest version
1 file
+
62
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
migrations/20240327_add_created_table.py
0 → 100644
+
62
−
0
Options
import
re
import
csv
import
dataset
from
datetime
import
datetime
import
rabbit_config
as
rcfg
def
fromisoformat
(
date_string
:
str
):
regex
=
re
.
compile
(
r
"
(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})\.(\d{1,6})
"
)
mo
=
re
.
search
(
regex
,
date_string
)
return
datetime
(
*
[
int
(
m
)
for
m
in
mo
.
groups
()])
def
upgrade
():
db_path
=
rcfg
.
db_path
db_name
=
"
user_reg.db
"
csv_filename
=
"
./migrations/account-registration-history.csv
"
db
=
dataset
.
connect
(
f
"
sqlite:///
{
db_path
}
/
{
db_name
}
"
)
# Get all username and last_update
usernames
=
db
.
query
(
"
SELECT username, last_update FROM users
"
)
users
=
{}
for
u
in
usernames
:
users
[
u
[
"
username
"
]]
=
{
"
username
"
:
u
[
"
username
"
],
"
date
"
:
fromisoformat
(
u
[
"
last_update
"
]),
"
source
"
:
"
account-web
"
,
}
# Get created from csv file
with
open
(
csv_filename
)
as
f
:
reader
=
csv
.
reader
(
f
,
delimiter
=
"
,
"
)
# Skip header
next
(
reader
)
for
row
in
reader
:
if
row
[
0
]
in
users
:
users
[
row
[
0
]][
"
date
"
]
=
fromisoformat
(
row
[
1
])
users
[
row
[
0
]][
"
source
"
]
=
row
[
2
]
else
:
users
[
row
[
0
]]
=
{
"
username
"
:
row
[
0
],
"
date
"
:
fromisoformat
(
row
[
1
]),
"
source
"
:
row
[
2
],
}
data_types
=
dict
(
username
=
db
.
types
.
text
,
date
=
db
.
types
.
datetime
,
source
=
db
.
types
.
text
)
# Sort the entries by date
sorted_users
=
sorted
(
users
.
values
(),
key
=
lambda
d
:
d
[
"
date
"
])
# Insert into database in chunks
table
=
db
[
"
user_created
"
]
table
.
insert_many
(
sorted_users
,
ensure
=
True
,
types
=
data_types
)
if
__name__
==
"
__main__
"
:
upgrade
()
Loading