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
35ccc43e
Commit
35ccc43e
authored
8 years ago
by
Cam Saül
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #3406 from metabase/fix-field-type-wonkiness
Fix field type wonkiness
parents
f13be5c6
1fca900a
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
src/metabase/db/migrations.clj
+23
-4
23 additions, 4 deletions
src/metabase/db/migrations.clj
src/metabase/models/field.clj
+6
-3
6 additions, 3 deletions
src/metabase/models/field.clj
with
29 additions
and
7 deletions
src/metabase/db/migrations.clj
+
23
−
4
View file @
35ccc43e
(
ns
metabase.db.migrations
"Clojure-land data migration definitions and fns for running them."
(
:require
[
clojure.tools.logging
:as
log
]
(
:require
[
clojure.string
:as
s
]
[
clojure.tools.logging
:as
log
]
(
metabase
[
config
:as
config
]
[
db
:as
db
]
[
driver
:as
driver
]
...
...
@@ -258,10 +259,28 @@
(
doseq
[[
_
t
]
old-base-type->new-type
]
(
assert
(
isa?
(
keyword
t
)
:type/*
))))
(
defmigration
migrate-base-types
;; migrate all of the old base + special types to the new ones.
;; This also takes care of any types that are already correct other than the fact that they're missing :type/ in the front.
;; This was a bug that existed for a bit in 0.20.0-SNAPSHOT but has since been corrected
(
defmigration
migrate-field-types
(
doseq
[[
old-type
new-type
]
old-special-type->new-type
]
(
db/update-where!
'Field
{
:special_type
old-type
}
;; migrate things like :timestamp_milliseconds -> :type/UNIXTimestampMilliseconds
(
db/update-where!
'Field
{
:%lower.special_type
(
s/lower-case
old-type
)}
:special_type
new-type
)
;; migrate things like :UNIXTimestampMilliseconds -> :type/UNIXTimestampMilliseconds
(
db/update-where!
'Field
{
:special_type
(
name
(
keyword
new-type
))}
:special_type
new-type
))
(
doseq
[[
old-type
new-type
]
old-base-type->new-type
]
(
db/update-where!
'Field
{
:base_type
old-type
}
;; migrate things like :DateTimeField -> :type/DateTime
(
db/update-where!
'Field
{
:%lower.base_type
(
s/lower-case
old-type
)}
:base_type
new-type
)
;; migrate things like :DateTime -> :type/DateTime
(
db/update-where!
'Field
{
:base_type
(
name
(
keyword
new-type
))}
:base_type
new-type
)))
;; if there were invalid field types in the database anywhere fix those so the new stricter validation logic doesn't blow up
(
defmigration
fix-invalid-field-types
(
db/update-where!
'Field
{
:base_type
[
:not-like
"type/%"
]}
:base_type
"type/*"
)
(
db/update-where!
'Field
{
:special_type
[
:not-like
"type/%"
]}
:special_type
nil
))
This diff is collapsed.
Click to expand it.
src/metabase/models/field.clj
+
6
−
3
View file @
35ccc43e
...
...
@@ -26,19 +26,22 @@
(
i/defentity
Field
:metabase_field
)
(
defn-
assert-valid-special-type
[{
special-type
:special_type
}]
(
defn-
check-valid-types
[{
base-type
:base_type,
special-type
:special_type
}]
(
when
base-type
(
assert
(
isa?
(
keyword
base-type
)
:type/*
)
(
str
"Invalid base type: "
base-type
)))
(
when
special-type
(
assert
(
isa?
(
keyword
special-type
)
:type/*
)
(
str
"Invalid special type: "
special-type
))))
(
defn-
pre-insert
[
field
]
(
assert
-valid-
special-
type
field
)
(
check
-valid-type
s
field
)
(
let
[
defaults
{
:display_name
(
humanization/name->human-readable-name
(
:name
field
))}]
(
merge
defaults
field
)))
(
defn-
pre-update
[
field
]
(
u/prog1
field
(
assert
-valid-
special-
type
field
)))
(
check
-valid-type
s
field
)))
(
defn-
pre-cascade-delete
[{
:keys
[
id
]}]
(
db/cascade-delete!
Field
:parent_id
id
)
...
...
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