Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
hive
hivemind
Commits
06322641
Commit
06322641
authored
4 years ago
by
Dariusz Kędzierski
Browse files
Options
Downloads
Patches
Plain Diff
Remove FKs before initial sync and recreate after initial sync
parent
e3cb8b90
No related branches found
Branches containing commit
No related tags found
Tags containing commit
4 merge requests
!456
Release candidate v1 24
,
!230
Setup monitoring with pghero
,
!138
Small typos fixed
,
!124
Remove FKs before initial sync and recreate after initial sync
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hive/db/db_state.py
+8
-8
8 additions, 8 deletions
hive/db/db_state.py
hive/db/schema.py
+25
-7
25 additions, 7 deletions
hive/db/schema.py
with
33 additions
and
15 deletions
hive/db/db_state.py
+
8
−
8
View file @
06322641
...
@@ -162,10 +162,9 @@ class DbState:
...
@@ -162,10 +162,9 @@ class DbState:
except
sqlalchemy
.
exc
.
ProgrammingError
as
ex
:
except
sqlalchemy
.
exc
.
ProgrammingError
as
ex
:
log
.
warning
(
"
Ignoring ex: {}
"
.
format
(
ex
))
log
.
warning
(
"
Ignoring ex: {}
"
.
format
(
ex
))
# TODO: #111
from
hive.db.schema
import
drop_fk
,
create_fk
#for key in cls._all_foreign_keys():
log
.
info
(
"
Dropping FKs
"
)
# log.info("Drop fk %s", key.name)
drop_fk
(
cls
.
db
())
# key.drop(engine)
log
.
info
(
"
[INIT] Finish pre-initial sync hooks
"
)
log
.
info
(
"
[INIT] Finish pre-initial sync hooks
"
)
...
@@ -241,12 +240,13 @@ class DbState:
...
@@ -241,12 +240,13 @@ class DbState:
update_active_starting_from_posts_on_block
(
last_imported_block
,
current_imported_block
)
update_active_starting_from_posts_on_block
(
last_imported_block
,
current_imported_block
)
log
.
info
(
"
Recreating FKs
"
)
from
hive.db.schema
import
create_fk
create_fk
(
cls
.
db
())
time_end
=
perf_counter
()
time_end
=
perf_counter
()
log
.
info
(
"
[INIT] update_all_posts_active executed in %fs
"
,
time_end
-
time_start
)
log
.
info
(
"
[INIT] update_all_posts_active executed in %fs
"
,
time_end
-
time_start
)
# TODO: #111
#for key in cls._all_foreign_keys():
# log.info("Create fk %s", key.name)
# key.create(engine)
@staticmethod
@staticmethod
def
status
():
def
status
():
...
...
This diff is collapsed.
Click to expand it.
hive/db/schema.py
+
25
−
7
View file @
06322641
...
@@ -183,11 +183,11 @@ def build_metadata():
...
@@ -183,11 +183,11 @@ def build_metadata():
sa
.
PrimaryKeyConstraint
(
'
author_id
'
,
'
permlink_id
'
,
'
voter_id
'
,
name
=
'
hive_votes_pk
'
),
sa
.
PrimaryKeyConstraint
(
'
author_id
'
,
'
permlink_id
'
,
'
voter_id
'
,
name
=
'
hive_votes_pk
'
),
sa
.
ForeignKeyConstraint
([
'
post_id
'
],
[
'
hive_posts.id
'
]),
sa
.
ForeignKeyConstraint
([
'
post_id
'
],
[
'
hive_posts.id
'
]
,
name
=
'
hive_votes_fk1
'
),
sa
.
ForeignKeyConstraint
([
'
voter_id
'
],
[
'
hive_accounts.id
'
]),
sa
.
ForeignKeyConstraint
([
'
voter_id
'
],
[
'
hive_accounts.id
'
]
,
name
=
'
hive_votes_fk2
'
),
sa
.
ForeignKeyConstraint
([
'
author_id
'
],
[
'
hive_accounts.id
'
]),
sa
.
ForeignKeyConstraint
([
'
author_id
'
],
[
'
hive_accounts.id
'
]
,
name
=
'
hive_votes_fk3
'
),
sa
.
ForeignKeyConstraint
([
'
permlink_id
'
],
[
'
hive_permlink_data.id
'
]),
sa
.
ForeignKeyConstraint
([
'
permlink_id
'
],
[
'
hive_permlink_data.id
'
]
,
name
=
'
hive_votes_fk4
'
),
sa
.
ForeignKeyConstraint
([
'
block_num
'
],
[
'
hive_blocks.num
'
]),
sa
.
ForeignKeyConstraint
([
'
block_num
'
],
[
'
hive_blocks.num
'
]
,
name
=
'
hive_votes_fk5
'
),
sa
.
Index
(
'
hive_votes_post_id_idx
'
,
'
post_id
'
),
sa
.
Index
(
'
hive_votes_post_id_idx
'
,
'
post_id
'
),
sa
.
Index
(
'
hive_votes_voter_id_idx
'
,
'
voter_id
'
),
sa
.
Index
(
'
hive_votes_voter_id_idx
'
,
'
voter_id
'
),
...
@@ -206,8 +206,8 @@ def build_metadata():
...
@@ -206,8 +206,8 @@ def build_metadata():
sa
.
Column
(
'
post_id
'
,
sa
.
Integer
,
nullable
=
False
),
sa
.
Column
(
'
post_id
'
,
sa
.
Integer
,
nullable
=
False
),
sa
.
Column
(
'
tag_id
'
,
sa
.
Integer
,
nullable
=
False
),
sa
.
Column
(
'
tag_id
'
,
sa
.
Integer
,
nullable
=
False
),
sa
.
PrimaryKeyConstraint
(
'
post_id
'
,
'
tag_id
'
,
name
=
'
hive_post_tags_pk1
'
),
sa
.
PrimaryKeyConstraint
(
'
post_id
'
,
'
tag_id
'
,
name
=
'
hive_post_tags_pk1
'
),
sa
.
ForeignKeyConstraint
([
'
post_id
'
],
[
'
hive_posts.id
'
]),
sa
.
ForeignKeyConstraint
([
'
post_id
'
],
[
'
hive_posts.id
'
]
,
name
=
'
hive_post_tags_fk1
'
),
sa
.
ForeignKeyConstraint
([
'
tag_id
'
],
[
'
hive_tag_data.id
'
]),
sa
.
ForeignKeyConstraint
([
'
tag_id
'
],
[
'
hive_tag_data.id
'
]
,
name
=
'
hive_post_tags_fk2
'
),
sa
.
Index
(
'
hive_post_tags_post_id_idx
'
,
'
post_id
'
),
sa
.
Index
(
'
hive_post_tags_post_id_idx
'
,
'
post_id
'
),
sa
.
Index
(
'
hive_post_tags_tag_id_idx
'
,
'
tag_id
'
)
sa
.
Index
(
'
hive_post_tags_tag_id_idx
'
,
'
tag_id
'
)
)
)
...
@@ -377,6 +377,24 @@ def teardown(db):
...
@@ -377,6 +377,24 @@ def teardown(db):
"""
Drop all tables
"""
"""
Drop all tables
"""
build_metadata
().
drop_all
(
db
.
engine
())
build_metadata
().
drop_all
(
db
.
engine
())
def
drop_fk
(
db
):
db
.
query_no_return
(
"
START TRANSACTION
"
)
for
table
in
build_metadata
().
sorted_tables
:
for
fk
in
table
.
foreign_keys
:
sql
=
"""
ALTER TABLE {} DROP CONSTRAINT {}
"""
.
format
(
table
.
name
,
fk
.
name
)
db
.
query_no_return
(
sql
)
db
.
query_no_return
(
"
COMMIT
"
)
def
create_fk
(
db
):
from
sqlalchemy.schema
import
AddConstraint
from
sqlalchemy
import
text
connection
=
db
.
engine
().
connect
()
connection
.
execute
(
text
(
"
START TRANSACTION
"
))
for
table
in
build_metadata
().
sorted_tables
:
for
fk
in
table
.
foreign_keys
:
connection
.
execute
(
AddConstraint
(
fk
.
constraint
))
connection
.
execute
(
text
(
"
COMMIT
"
))
def
setup
(
db
):
def
setup
(
db
):
"""
Creates all tables and seed data
"""
"""
Creates all tables and seed data
"""
# initialize schema
# initialize schema
...
...
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