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
a2f3656b
Unverified
Commit
a2f3656b
authored
1 year ago
by
Cal Herries
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Only copy active fields and tables with data/with-temp-copy-of-db (#39862)
parent
ef9fb057
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/metabase/test/data/impl.clj
+15
-9
15 additions, 9 deletions
test/metabase/test/data/impl.clj
with
15 additions
and
9 deletions
test/metabase/test/data/impl.clj
+
15
−
9
View file @
a2f3656b
...
...
@@ -133,7 +133,8 @@
[
database-id
:-
::lib.schema.id/database
]
(
t2/select-fn->pk
(
juxt
(
constantly
database-id
)
:name
)
[
:model/Table
:id
:name
]
:db_id
database-id
))
:db_id
database-id
:active
true
))
(
mu/defn
^
:private
build-field-lookup-map
[
table-id
:-
::lib.schema.id/table
]
...
...
@@ -169,7 +170,7 @@
(
defn-
table-id-from-app-db
[
db-id
table-name
]
(
t2/select-one-pk
[
Table
:id
]
:db_id
db-id,
:name
table-name
))
(
t2/select-one-pk
[
Table
:id
]
:db_id
db-id,
:name
table-name
,
:active
true
))
(
defn-
throw-unfound-table-error
[
db-id
table-name
]
(
let
[{
driver
:engine,
db-name
:name
}
(
t2/select-one
[
:model/Database
:name
:engine
]
:id
db-id
)]
...
...
@@ -198,7 +199,8 @@
(
str
(
t2/select-one-fn
(
fn
[
field
]
(
qualified-field-name
(
:parent_id
field
)
(
:name
field
)))
[
:model/Field
:parent_id
:name
]
:id
parent-id
)
:id
parent-id
:active
true
)
\.
field-name
)
field-name
))
...
...
@@ -244,11 +246,11 @@
(
defn-
copy-table-fields!
[
old-table-id
new-table-id
]
(
t2/insert!
Field
(
for
[
field
(
t2/select
Field
:table_id
old-table-id
{
:order-by
[[
:id
:asc
]]})]
(
for
[
field
(
t2/select
Field
:table_id
old-table-id
,
:active
true,
{
:order-by
[[
:id
:asc
]]})]
(
->
field
(
dissoc
:id
:fk_target_field_id
)
(
assoc
:table_id
new-table-id
))))
;; now copy the FieldValues as well.
(
let
[
old-field-id->name
(
t2/select-pk->fn
:name
Field
:table_id
old-table-id
)
new-field-name->id
(
t2/select-fn->pk
:name
Field
:table_id
new-table-id
)
(
let
[
old-field-id->name
(
t2/select-pk->fn
:name
Field
:table_id
old-table-id
:active
true
)
new-field-name->id
(
t2/select-fn->pk
:name
Field
:table_id
new-table-id
:active
true
)
old-field-values
(
t2/select
FieldValues
:field_id
[
:in
(
set
(
keys
old-field-id->name
))])]
(
t2/insert!
FieldValues
(
for
[{
old-field-id
:field_id,
:as
field-values
}
old-field-values
...
...
@@ -262,7 +264,7 @@
(
update
:human_readable_values
not-empty
))))))
(
defn-
copy-db-tables!
[
old-db-id
new-db-id
]
(
let
[
old-tables
(
t2/select
Table
:db_id
old-db-id
{
:order-by
[[
:id
:asc
]]})
(
let
[
old-tables
(
t2/select
Table
:db_id
old-db-id
,
:active
true,
{
:order-by
[[
:id
:asc
]]})
new-table-ids
(
t2/insert-returning-pks!
Table
(
for
[
table
old-tables
]
(
->
table
(
dissoc
:id
)
(
assoc
:db_id
new-db-id
))))]
...
...
@@ -273,8 +275,8 @@
(
doseq
[{
:keys
[
source-field
source-table
target-field
target-table
]}
(
mdb.query/query
{
:select
[[
:source-field.name
:source-field
]
[
:source-table.name
:source-table
]
[
:target-field.name
:target-field
]
[
:target-table.name
:target-table
]]
[
:target-field.name
:target-field
]
[
:target-table.name
:target-table
]]
:from
[[
:metabase_field
:source-field
]]
:left-join
[[
:metabase_table
:source-table
]
[
:=
:source-field.table_id
:source-table.id
]
[
:metabase_field
:target-field
]
[
:=
:source-field.fk_target_field_id
:target-field.id
]
...
...
@@ -282,6 +284,10 @@
:where
[
:and
[
:=
:source-table.db_id
old-db-id
]
[
:=
:target-table.db_id
old-db-id
]
:source-field.active
:target-field.active
:source-table.active
:target-table.active
[
:not=
:source-field.fk_target_field_id
nil
]]})]
(
t2/update!
Field
(
the-field-id
(
the-table-id
new-db-id
source-table
)
source-field
)
{
:fk_target_field_id
(
the-field-id
(
the-table-id
new-db-id
target-table
)
target-field
)})))
...
...
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