Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
08b6fcdc
Commit
08b6fcdc
authored
8 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
fix issue #2632 where self-referencing columns were causing FK constraint errors on migration.
parent
f1af87c6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
resources/log4j.properties
+0
-1
0 additions, 1 deletion
resources/log4j.properties
src/metabase/cmd/load_from_h2.clj
+26
-10
26 additions, 10 deletions
src/metabase/cmd/load_from_h2.clj
with
26 additions
and
11 deletions
resources/log4j.properties
+
0
−
1
View file @
08b6fcdc
...
...
@@ -18,7 +18,6 @@ log4j.appender.metabase=metabase.logger.Appender
# customizations to logging by package
log4j.logger.metabase
=
INFO
log4j.logger.metabase.db
=
DEBUG
log4j.logger.metabase.driver
=
DEBUG
log4j.logger.metabase.query-processor
=
DEBUG
log4j.logger.metabase.sync-database
=
DEBUG
This diff is collapsed.
Click to expand it.
src/metabase/cmd/load_from_h2.clj
+
26
−
10
View file @
08b6fcdc
...
...
@@ -32,7 +32,8 @@
[
table
:refer
[
Table
]]
[
user
:refer
[
User
]]
[
view-log
:refer
[
ViewLog
]])
[
metabase.util
:as
u
]))
[
metabase.util
:as
u
]
[
clojure.set
:as
set
]))
(
def
^
:private
entities
"Entities in the order they should be serialized/deserialized.
...
...
@@ -67,6 +68,27 @@
Label
CardLabel
])
(
defn-
insert-entity
[
e
objs
]
(
print
(
u/format-color
'blue
"Transfering %d instances of %s..."
(
count
objs
)
(
:name
e
)))
(
flush
)
;; The connection closes prematurely on occasion when we're inserting thousands of rows at once. Break into smaller chunks so connection stays alive
(
doseq
[
chunk
(
partition-all
300
objs
)]
(
print
(
color/blue
\.
))
(
flush
)
(
k/insert
e
(
k/values
chunk
)))
(
println
(
color/green
"[OK]"
)))
(
defn-
insert-self-referencing-entity
[
e
objs
]
(
let
[
self-ref-attr
(
condp
=
e
RawColumn
:fk_target_column_id
Field
:fk_target_field_id
)
self-referencing
(
filter
self-ref-attr
objs
)
others
(
set/difference
(
set
objs
)
(
set
self-referencing
))]
;; first insert the non-self-referencing objects
(
insert-entity
e
others
)
;; then insert the rest, which should be safe to insert now
(
insert-entity
e
self-referencing
)))
(
defn
load-from-h2
"Transfer data from existing H2 database to the newly created (presumably MySQL or Postgres) DB specified by env vars.
Intended as a tool for upgrading from H2 to a 'real' Database.
...
...
@@ -82,12 +104,6 @@
:let
[
objs
(
kdb/with-db
h2-db
(
k/select
(
k/database
e
h2-db
)))]
:when
(
seq
objs
)]
(
print
(
u/format-color
'blue
"Transfering %d instances of %s..."
(
count
objs
)
(
:name
e
)))
(
flush
)
;; The connection closes prematurely on occasion when we're inserting thousands of rows at once. Break into smaller chunks so connection stays alive
(
doseq
[
chunk
(
partition-all
300
objs
)]
(
print
(
color/blue
\.
))
(
flush
)
(
k/insert
e
(
k/values
chunk
)))
(
println
(
color/green
"[OK]"
))))))
(
if-not
(
contains?
#
{
RawColumn
Field
}
e
)
(
insert-entity
e
objs
)
(
insert-self-referencing-entity
e
objs
))))))
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