-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from lipas-liikuntapaikat/type-code-renewal-3
Type code renewal 3
- Loading branch information
Showing
47 changed files
with
10,066 additions
and
1,684 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ | |
(:require | ||
[clojure.tools.namespace.repl] | ||
[integrant.repl :refer [reset reset-all halt go]] | ||
[integrant.repl.state])) | ||
[integrant.repl.state] | ||
[lipas.data.prop-types :as prop-types])) | ||
|
||
(integrant.repl/set-prep! (fn [] | ||
(dissoc @(requiring-resolve 'lipas.backend.config/system-config) :lipas/nrepl))) | ||
|
@@ -35,6 +36,11 @@ | |
(assert-running-system) | ||
(:lipas/search (current-system))) | ||
|
||
(defn ptv | ||
[] | ||
(assert-running-system) | ||
(:lipas/ptv (current-system))) | ||
|
||
(defn reindex-search! | ||
[] | ||
((requiring-resolve 'lipas.backend.search-indexer/main) (db) (search) "search")) | ||
|
@@ -61,4 +67,104 @@ | |
|
||
(require '[migratus.core :as migratus]) | ||
(migratus/create nil "activities_status" :sql) | ||
(migratus/create nil "roles" :edn) | ||
(migratus/create nil "year_round_use" :sql) | ||
|
||
(require '[lipas.maintenance :as maintenance]) | ||
(require '[lipas.backend.core :as core]) | ||
|
||
(def robot (core/get-user (db) "[email protected]")) | ||
|
||
(maintenance/merge-types (db) (search) (ptv) robot 4530 4510) | ||
(maintenance/merge-types (db) (search) (ptv) robot 4520 4510) | ||
(maintenance/merge-types (db) (search) (ptv) robot 4310 4320) | ||
|
||
(require '[lipas.data.types :as types]) | ||
(require '[lipas.data.types-old :as types-old]) | ||
(require '[lipas.data.prop-types :as prop-types]) | ||
(require '[lipas.data.prop-types-old :as prop-types-old]) | ||
(require '[clojure.set :as set]) | ||
|
||
(def new-types (set/difference | ||
(set (keys types/all)) | ||
(set (keys types-old/all)))) | ||
|
||
(require '[clojure.string :as str]) | ||
|
||
(for [type-code (conj new-types 113)] | ||
(println | ||
(format "INSERT INTO public.liikuntapaikkatyyppi( | ||
id, tyyppikoodi, nimi_fi, nimi_se, kuvaus_fi, kuvaus_se, liikuntapaikkatyyppi_alaryhma, geometria, tason_nimi, nimi_en, kuvaus_en) | ||
VALUES (%s, %s, '%s', '%s', '%s', '%s', %s, '%s', '%s', '%s', '%s');" | ||
type-code | ||
type-code | ||
(get-in types/all [type-code :name :fi]) | ||
(get-in types/all [type-code :name :se]) | ||
(get-in types/all [type-code :description :fi]) | ||
(get-in types/all [type-code :description :se]) | ||
(get-in types/all [type-code :sub-category]) | ||
(get-in types/all [type-code :geometry-type]) | ||
(-> types/all | ||
(get-in [type-code :name :fi]) | ||
csk/->snake_case | ||
(str/replace "ä" "a") | ||
(str/replace "ö" "o") | ||
(str/replace #"[^a-zA-Z]" "") | ||
(->> (str "lipas_" type-code "_"))) | ||
(get-in types/all [type-code :name :en]) | ||
(get-in types/all [type-code :description :en])))) | ||
|
||
(def new-props (set/difference | ||
(set (keys prop-types/all)) | ||
(set (keys prop-types-old/all)))) | ||
|
||
new-props | ||
|
||
(require '[camel-snake-kebab.core :as csk]) | ||
(def legacy-mapping (into {} (for [p new-props] | ||
[(csk/->camelCaseKeyword p) p]))) | ||
|
||
(keys legacy-mapping) | ||
|
||
(def legacy-mapping-reverse (set/map-invert legacy-mapping)) | ||
|
||
(require '[lipas.data.prop-types :as prop-types]) | ||
|
||
(def data-types | ||
"Legacy lipas supports only these. Others will be treated as strings" | ||
{"boolean" "boolean" | ||
"numeric" "numberic" | ||
"string" "string"}) | ||
|
||
(doseq [[legacy-prop-k prop-k] legacy-mapping] | ||
(println | ||
(format "INSERT INTO public.ominaisuustyypit( | ||
nimi_fi, tietotyyppi, kuvaus_fi, nimi_se, kuvaus_se, ui_nimi_fi, nimi_en, kuvaus_en, handle) | ||
VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s');" | ||
(csk/->snake_case (get-in prop-types/all [prop-k :name :fi])) | ||
(get data-types (get-in prop-types/all [prop-k :data-type]) "string") | ||
(get-in prop-types/all [prop-k :description :fi]) | ||
(get-in prop-types/all [prop-k :name :se]) | ||
(get-in prop-types/all [prop-k :description :se]) | ||
(get-in prop-types/all [prop-k :name :fi]) | ||
(get-in prop-types/all [prop-k :name :en]) | ||
(get-in prop-types/all [prop-k :description :en]) | ||
(name legacy-prop-k)))) | ||
|
||
(doseq [p new-props | ||
[type-code m] types/all] | ||
(when (contains? (set (keys (:props m))) p) | ||
(println (str "-- Type " type-code)) | ||
(println (str "-- prop " p)) | ||
(println | ||
(format | ||
"INSERT INTO public.tyypinominaisuus( | ||
liikuntapaikkatyyppi_id, ominaisuustyyppi_id, prioriteetti) | ||
VALUES (%s, %s, %s);" | ||
(format "(select id from liikuntapaikkatyyppi where tyyppikoodi = %s)" | ||
type-code) | ||
(format "(select id from ominaisuustyypit where handle = '%s')" | ||
(name (legacy-mapping-reverse p))) | ||
(get-in types/all [type-code :props p :priority]))))) | ||
|
||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
webapp/resources/migrations/20241103113824-year-round-use.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
UPDATE sports_site | ||
SET document = jsonb_set( | ||
document, | ||
'{properties}', | ||
(document::jsonb->'properties')::jsonb - 'year-round-use?' | ||
) | ||
WHERE document::jsonb->'properties' ? 'year-round-use?'; |
7 changes: 7 additions & 0 deletions
7
webapp/resources/migrations/20241103113824-year-round-use.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
UPDATE sports_site | ||
SET document = jsonb_set(document, '{properties, year-round-use?}', 'true') | ||
WHERE id IN ( | ||
SELECT id | ||
FROM sports_site_current | ||
WHERE document::jsonb->'properties'->>'winter-usage?' = 'true' OR | ||
document::jsonb->'properties'->>'summer-usage?' = 'true') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.