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
ba988005
Commit
ba988005
authored
8 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
Remove Labels -> Collections data migration
parent
c38e86a5
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
src/metabase/db/migrations.clj
+0
-33
0 additions, 33 deletions
src/metabase/db/migrations.clj
with
0 additions
and
33 deletions
src/metabase/db/migrations.clj
+
0
−
33
View file @
ba988005
...
...
@@ -320,36 +320,3 @@
:base_type
"type/*"
)
(
db/update-where!
'Field
{
:special_type
[
:not-like
"type/%"
]}
:special_type
nil
))
;;; +------------------------------------------------------------------------------------------------------------------------+
;;; | PEMISSIONS COLLECTIONS |
;;; +------------------------------------------------------------------------------------------------------------------------+
(
s/defn
^
:private
^
:always-validate
random-color
:-
collection/hex-color-regex
[]
(
format
"#%06X"
(
rand-int
(
Math/pow
256
3
))))
(
defn-
get-or-create-collection!
"Create a new Collection for LABEL (if needed). If label had a color, keep it, otherwise give it a random new one."
[{
label-name
:name,
icon
:icon
}]
(
or
(
Collection
:name
label-name
)
(
println
(
u/format-color
'green
"Creating a new collection for label '%s'..."
label-name
))
(
db/insert!
Collection
:name
label-name
:color
(
or
(
re-matches
collection/hex-color-regex
icon
)
(
random-color
)))))
(
defn-
add-label-cards-to-collection!
"Add cards that have LABEL to COLLECTION, if they're not already in a Collection."
[{
label-name
:name,
:as
label
}
collection
]
(
doseq
[
card-label
(
db/select
CardLabel
:label_id
(
u/get-id
label
))]
(
when-let
[
card
(
db/select-one
Card
:id
(
:card_id
card-label
)
,
:collection_id
nil
)]
(
println
(
u/format-color
'blue
"Adding card '%s' to collection '%s'..."
(
:name
card
)
label-name
))
(
db/update!
Card
(
u/get-id
card
)
:collection_id
(
u/get-id
collection
)))))
;; create new Collections for existing Labels, and add cards to the one of the newly created collections for them
(
defmigration
^
{
:author
"camsaul"
,
:added
"0.22.0"
}
create-collections-for-labels
(
doseq
[
label
(
db/select
Label
{
:order-by
[
:%lower.name
]})]
(
add-label-cards-to-collection!
label
(
get-or-create-collection!
label
))))
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