Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
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
Container Registry
Model registry
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
5b8b1a43
Commit
5b8b1a43
authored
9 years ago
by
Erik Johnston
Browse files
Options
Downloads
Patches
Plain Diff
Split setuping up and processing of tables
parent
40cbd6b6
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
scripts/port_from_sqlite_to_postgres.py
+23
-8
23 additions, 8 deletions
scripts/port_from_sqlite_to_postgres.py
with
23 additions
and
8 deletions
scripts/port_from_sqlite_to_postgres.py
+
23
−
8
View file @
5b8b1a43
...
@@ -168,7 +168,7 @@ class Porter(object):
...
@@ -168,7 +168,7 @@ class Porter(object):
)
)
@defer.inlineCallbacks
@defer.inlineCallbacks
def
handle
_table
(
self
,
table
):
def
setup
_table
(
self
,
table
):
def
delete_all
(
txn
):
def
delete_all
(
txn
):
txn
.
execute
(
txn
.
execute
(
"
DELETE FROM port_from_sqlite3 WHERE table_name = %s
"
,
"
DELETE FROM port_from_sqlite3 WHERE table_name = %s
"
,
...
@@ -287,6 +287,10 @@ class Porter(object):
...
@@ -287,6 +287,10 @@ class Porter(object):
postgres_size
=
yield
self
.
postgres_store
.
execute
(
get_table_size
)
postgres_size
=
yield
self
.
postgres_store
.
execute
(
get_table_size
)
defer
.
returnValue
((
table
,
postgres_size
,
table_size
,
next_chunk
))
@defer.inlineCallbacks
def
handle_table
(
self
,
table
,
postgres_size
,
table_size
,
next_chunk
):
if
not
table_size
:
if
not
table_size
:
return
return
...
@@ -364,14 +368,14 @@ class Porter(object):
...
@@ -364,14 +368,14 @@ class Porter(object):
self
.
postgres_store
=
Store
(
postgres_db_pool
,
postgres_engine
)
self
.
postgres_store
=
Store
(
postgres_db_pool
,
postgres_engine
)
# Step 1. Set up databases.
# Step 1. Set up databases.
self
.
progress
.
on_prepare_sql
ite
(
)
self
.
progress
.
set_state
(
"
Preparing SQL
ite
3
"
)
self
.
setup_db
(
sqlite_config
,
sqlite_engine
)
self
.
setup_db
(
sqlite_config
,
sqlite_engine
)
self
.
progress
.
on_prepare_p
ostgre
s
(
)
self
.
progress
.
set_state
(
"
Preparing P
ostgre
SQL
"
)
self
.
setup_db
(
postgres_config
,
postgres_engine
)
self
.
setup_db
(
postgres_config
,
postgres_engine
)
# Step 2. Get tables.
# Step 2. Get tables.
self
.
progress
.
f
etching
_
tables
(
)
self
.
progress
.
set_state
(
"
F
etching
tables
"
)
sqlite_tables
=
yield
self
.
sqlite_store
.
_simple_select_onecol
(
sqlite_tables
=
yield
self
.
sqlite_store
.
_simple_select_onecol
(
table
=
"
sqlite_master
"
,
table
=
"
sqlite_master
"
,
keyvalues
=
{
keyvalues
=
{
...
@@ -390,7 +394,7 @@ class Porter(object):
...
@@ -390,7 +394,7 @@ class Porter(object):
tables
=
set
(
sqlite_tables
)
&
set
(
postgres_tables
)
tables
=
set
(
sqlite_tables
)
&
set
(
postgres_tables
)
self
.
progress
.
prepar
ing
_
tables
(
)
self
.
progress
.
set_state
(
"
Creat
ing
tables
"
)
logger
.
info
(
"
Found %d tables
"
,
len
(
tables
))
logger
.
info
(
"
Found %d tables
"
,
len
(
tables
))
...
@@ -409,10 +413,12 @@ class Porter(object):
...
@@ -409,10 +413,12 @@ class Porter(object):
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
info
(
"
Failed to create port table: %s
"
,
e
)
logger
.
info
(
"
Failed to create port table: %s
"
,
e
)
# Process tables.
self
.
progress
.
set_state
(
"
Preparing tables
"
)
yield
defer
.
gatherResults
(
# Set up tables.
setup_res
=
yield
defer
.
gatherResults
(
[
[
self
.
handle
_table
(
table
)
self
.
setup
_table
(
table
)
for
table
in
tables
for
table
in
tables
if
table
not
in
[
"
schema_version
"
,
"
applied_schema_deltas
"
]
if
table
not
in
[
"
schema_version
"
,
"
applied_schema_deltas
"
]
and
not
table
.
startswith
(
"
sqlite_
"
)
and
not
table
.
startswith
(
"
sqlite_
"
)
...
@@ -420,6 +426,15 @@ class Porter(object):
...
@@ -420,6 +426,15 @@ class Porter(object):
consumeErrors
=
True
,
consumeErrors
=
True
,
)
)
# Process tables.
yield
defer
.
gatherResults
(
[
self
.
handle_table
(
*
res
)
for
res
in
setup_res
],
consumeErrors
=
True
,
)
self
.
progress
.
done
()
self
.
progress
.
done
()
except
:
except
:
global
end_error_exec_info
global
end_error_exec_info
...
...
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