Skip to content
Snippets Groups Projects
Unverified Commit a1aebe90 authored by bryan's avatar bryan Committed by GitHub
Browse files

remove internal user on rollback + test (#35684)

* remove internal user on rollback + test

* fix naming + add newline

* fix typo

* rollback change to migration changeset ID

- since it would alter the checksum for it
parent 931029e0
No related merge requests found
......@@ -16064,6 +16064,15 @@ databaseChangeLog:
newDataType: VARCHAR(32)
rollback: # not necessary
 
- changeSet:
id: v48.00-054
author: escherize
comment: Added 0.48.0 - no-op migration to remove Internal Metabase User on downgrade
changes:
- comment: "No operation performed for this changeset on execution."
rollback:
- sql: DELETE FROM core_user WHERE id = 13371338;
# >>>>>>>>>> DO NOT ADD NEW MIGRATIONS BELOW THIS LINE! ADD THEM ABOVE <<<<<<<<<<
 
########################################################################################################################
......
......@@ -1338,8 +1338,8 @@
(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!]
(testing "Migration v48.00-050, and v48.00-54"
(impl/test-migrations "v48.00-054" [migrate!]
(let [{:keys [db-type ^javax.sql.DataSource data-source]} mdb.connection/*application-db*
_db-audit-id (first (t2/insert-returning-pks! (t2/table-name :model/Database)
{:name "Audit DB"
......@@ -1359,19 +1359,23 @@
{:name "Normal Collection"
:type nil
:slug "normal_collection"}))
_internal-user-id (first (t2/insert-returning-pks! :model/User
{:id 13371338
:first_name "Metabase Internal User"
:email "internal@metabase.com"
:password (str (random-uuid))}))
original-db (t2/query {:datasource data-source} "SELECT * FROM metabase_database")
original-collections (t2/query {:datasource data-source} "SELECT * FROM collection")]
;; Verify that data is inserted correctly
(is (= 2 (count original-db)))
(is (= 2 (count original-collections)))
original-collections (t2/query {:datasource data-source} "SELECT * FROM collection")
check-before (fn []
(is (partial= (set (map :name original-db))
(set (map :name (t2/query {:datasource data-source} "SELECT name FROM metabase_database")))))
(is (partial= (set (map :name original-collections))
(set (map :name (t2/query {:datasource data-source} "SELECT name FROM collection")))))
(is (= 1 (count (t2/query "SELECT * FROM core_user WHERE id = 13371338")))))]
(check-before) ;; Verify that data is inserted correctly
(migrate!) ;; no-op forward migration
;; Verify that forward migration did not change data
(is (partial= (set (map :name original-db))
(set (map :name (t2/query {:datasource data-source} "SELECT name FROM metabase_database")))))
(is (partial= (set (map :name original-collections))
(set (map :name (t2/query {:datasource data-source} "SELECT name FROM collection")))))
(check-before) ;; Verify that forward migration did not change data
(db.setup/migrate! db-type data-source :down 47)
......@@ -1379,4 +1383,5 @@
(is (= 1 (count (t2/query "SELECT * FROM metabase_database"))))
(is (= 1 (count (t2/query "SELECT * FROM collection"))))
(is (= 0 (count (t2/query "SELECT * FROM metabase_database WHERE is_audit = TRUE"))))
(is (= 0 (count (t2/query "SELECT * FROM collection WHERE type = 'instance_analytics'"))))))))
(is (= 0 (count (t2/query "SELECT * FROM collection WHERE type = 'instance_analytics'"))))
(is (= 0 (count (t2/query "SELECT * FROM core_user WHERE id = 13371338"))))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment