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
6da08bfa
Unverified
Commit
6da08bfa
authored
1 year ago
by
Cal Herries
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add migration to remove FK target fields for previously inactive fields (#35531)
parent
704d45bf
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
resources/migrations/000_migrations.yaml
+27
-0
27 additions, 0 deletions
resources/migrations/000_migrations.yaml
test/metabase/db/schema_migrations_test.clj
+48
-10
48 additions, 10 deletions
test/metabase/db/schema_migrations_test.clj
with
75 additions
and
10 deletions
resources/migrations/000_migrations.yaml
+
27
−
0
View file @
6da08bfa
...
...
@@ -16027,6 +16027,33 @@ databaseChangeLog:
- sql: DELETE FROM metabase_database WHERE is_audit = TRUE;
- sql: DELETE FROM collection WHERE type = 'instance_analytics';
- changeSet:
id: v48.00-051
author: calherries
comment: Migrate metabase_field when the fk target field is inactive
changes:
- sql:
dbms: mariadb,mysql
sql: >-
UPDATE metabase_field AS a
JOIN metabase_field AS b ON b.id = a.fk_target_field_id
SET a.fk_target_field_id = NULL,
a.semantic_type = NULL
WHERE b.active = FALSE;
- sql:
dbms: postgresql,h2
sql: >-
UPDATE metabase_field
SET fk_target_field_id = NULL,
semantic_type = NULL
WHERE fk_target_field_id IN (
SELECT id
FROM metabase_field
WHERE active = FALSE
);
rollback: # no change
# >>>>>>>>>> DO NOT ADD NEW MIGRATIONS BELOW THIS LINE! ADD THEM ABOVE <<<<<<<<<<
########################################################################################################################
...
...
This diff is collapsed.
Click to expand it.
test/metabase/db/schema_migrations_test.clj
+
48
−
10
View file @
6da08bfa
...
...
@@ -799,17 +799,17 @@
:updated_at
:%now
:active
true
}))
field-1-id
(
first
(
t2/insert-returning-pks!
(
t2/table-name
Field
)
{
:name
"F1"
:table_id
table-id
:base_type
"type/Text"
:database_type
"TEXT"
:created_at
:%now
:updated_at
:%now
}))
:table_id
table-id
:base_type
"type/Text"
:database_type
"TEXT"
:created_at
:%now
:updated_at
:%now
}))
field-2-id
(
first
(
t2/insert-returning-pks!
(
t2/table-name
Field
)
{
:name
"F2"
:table_id
table-id
:base_type
"type/Text"
:database_type
"TEXT"
:created_at
:%now
:updated_at
:%now
}))
:table_id
table-id
:base_type
"type/Text"
:database_type
"TEXT"
:created_at
:%now
:updated_at
:%now
}))
_
(
t2/insert!
(
t2/table-name
Dimension
)
{
:field_id
field-1-id
:name
"F1 D1"
:type
"internal"
...
...
@@ -1299,6 +1299,44 @@
:table_id
6
}}
(
t2/select-one
:model/AuditLog
)))))))))
(
deftest
inactive-fields-fk-migration-test
(
testing
"Migration v48.00-051"
(
impl/test-migrations
[
"v48.00-051"
]
[
migrate!
]
(
let
[
database-id
(
first
(
t2/insert-returning-pks!
(
t2/table-name
Database
)
{
:details
"{}"
:engine
"h2"
:is_sample
false
:name
"populate-collection-created-at-test-db"
}))
table-1-id
(
first
(
t2/insert-returning-pks!
(
t2/table-name
Table
)
{
:db_id
database-id
:name
"Table 1"
:created_at
:%now
:updated_at
:%now
:active
true
}))
table-2-id
(
first
(
t2/insert-returning-pks!
(
t2/table-name
Table
)
{
:db_id
database-id
:name
"Table 2"
:created_at
:%now
:updated_at
:%now
:active
true
}))
field-1-id
(
first
(
t2/insert-returning-pks!
(
t2/table-name
Field
)
{
:name
"F1"
:table_id
table-1-id
:base_type
"type/Text"
:database_type
"TEXT"
:created_at
:%now
:updated_at
:%now
:active
false
}))
field-2-id
(
first
(
t2/insert-returning-pks!
(
t2/table-name
Field
)
{
:name
"F2"
:table_id
table-2-id
:base_type
"type/Text"
:database_type
"TEXT"
:created_at
:%now
:updated_at
:%now
:active
true
:fk_target_field_id
field-1-id
:semantic_type
"type/FK"
}))]
(
migrate!
)
(
is
(
=?
{
:fk_target_field_id
nil
:semantic_type
nil
}
(
t2/select-one
(
t2/table-name
:model/Field
)
:id
field-2-id
)))))))
(
deftest
audit-v2-downgrade-test
(
testing
"Migration v48.00-050"
(
impl/test-migrations
"v48.00-050"
[
migrate!
]
...
...
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