The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Move auth_identity.confirmed_at migrations from v59 to v63 ids (#83425)
bryandf84accc3c2a
diff --git a/resources/migrations/059_update_migrations.yaml b/resources/migrations/059_update_migrations.yamlindex 1875658ee0d..33ba1571959 100644--- a/resources/migrations/059_update_migrations.yaml+++ b/resources/migrations/059_update_migrations.yaml@@ -3503,29 +3503,6 @@ databaseChangeLog:- customChange:class: "metabase.app_db.custom_migrations.DropMedallionNamesForDataLayer"- - changeSet:- id: v59.2026-07-10T22:29:16- author: escherize- comment: Add confirmed_at to auth_identity so MFA enrollment state is queryable in SQL- changes:- - addColumn:- tableName: auth_identity- columns:- - column:- name: confirmed_at- type: ${timestamp_type}- remarks: When this identity was confirmed (e.g. MFA enrollment completed). Null = unconfirmed.- constraints:- nullable: true-- - changeSet:- id: v59.2026-07-10T22:29:17- author: escherize- comment: Backfill auth_identity.confirmed_at from the (possibly encrypted) credentials JSON- changes:- - customChange:- class: "metabase.app_db.custom_migrations.BackfillMfaConfirmedAt"-# >>>>>>>>>> DO NOT ADD NEW MIGRATIONS BELOW THIS LINE! ADD THEM ABOVE <<<<<<<<<<########################################################################################################################diff --git a/resources/migrations/063/20260710_auth_identity_confirmed_at.yaml b/resources/migrations/063/20260710_auth_identity_confirmed_at.yamlnew file mode 100644index 00000000000..e14579dff9c--- /dev/null+++ b/resources/migrations/063/20260710_auth_identity_confirmed_at.yaml@@ -0,0 +1,51 @@+## Adds auth_identity.confirmed_at so MFA enrollment state is queryable in SQL, and backfills it.+##+## These changeSets originally shipped in 059_update_migrations.yaml as v59.2026-07-10T22:29:16 and+## v59.2026-07-10T22:29:17, but the feature only shipped in 63. No v59-v62 jar knows those ids, so+## `migrate down` below 63 could not roll them back and left the column and changelog rows behind. The+## first changeSet retires the stale v59 rows; the addColumn is guarded so instances that already have+## the column just mark it ran. DATABASECHANGELOG is unquoted on purpose: it folds to the table's actual+## case on postgres (lowercase) and h2 (uppercase), and matches it exactly on mysql/mariadb.++databaseChangeLog:+ - changeSet:+ id: v63.2026-07-10T22:29:15+ author: escherize+ comment: Retire the misnumbered v59 changelog rows for auth_identity.confirmed_at+ changes:+ - sql:+ sql: >-+ DELETE FROM DATABASECHANGELOG WHERE id IN (+ 'v59.2026-07-10T22:29:16',+ 'v59.2026-07-10T22:29:17'+ );+ rollback: # nothing to undo - these rows should not exist++ - changeSet:+ id: v63.2026-07-10T22:29:16+ author: escherize+ comment: Add confirmed_at to auth_identity so MFA enrollment state is queryable in SQL+ preConditions:+ - onFail: MARK_RAN+ - not:+ - columnExists:+ tableName: auth_identity+ columnName: confirmed_at+ changes:+ - addColumn:+ tableName: auth_identity+ columns:+ - column:+ name: confirmed_at+ type: ${timestamp_type}+ remarks: When this identity was confirmed (e.g. MFA enrollment completed). Null = unconfirmed.+ constraints:+ nullable: true++ - changeSet:+ id: v63.2026-07-10T22:29:17+ author: escherize+ comment: Backfill auth_identity.confirmed_at from the (possibly encrypted) credentials JSON+ changes:+ - customChange:+ class: "metabase.app_db.custom_migrations.BackfillMfaConfirmedAt"diff --git a/test/metabase/app_db/custom_migrations_test.clj b/test/metabase/app_db/custom_migrations_test.cljindex d97a1098dc1..23383eaeae7 100644--- a/test/metabase/app_db/custom_migrations_test.clj+++ b/test/metabase/app_db/custom_migrations_test.clj@@ -2957,34 +2957,6 @@(testing "Native transform strategy is stripped (can't resolve source table)"(is (not (contains? (get-source native-id) :source-incremental-strategy))))))))-(deftest backfill-mfa-confirmed-at-test- (testing "v59.2026-07-10T22:29:17: confirmed_at is lifted out of the credentials JSON into the column"- (encryption-test/with-secret-key "backfill-mfa-test-key-1234"- (impl/test-migrations ["v59.2026-07-10T22:29:17"] [migrate!]- (let [confirmed-at "2026-07-01T12:00:00Z"- insert-identity!- (fn [user-id credentials-str]- (t2/insert-returning-pk! :auth_identity {:user_id user-id- :provider "totp"- :credentials credentials-str- :created_at :%now- :updated_at :%now}))- enc-confirmed (insert-identity! (:id (new-instance-with-default :core_user))- (encryption/maybe-encrypt- (json/encode {:secret "s1" :confirmed_at confirmed-at})))- plain-confirmed (insert-identity! (:id (new-instance-with-default :core_user))- (json/encode {:secret "s2" :confirmed_at confirmed-at}))- pending (insert-identity! (:id (new-instance-with-default :core_user))- (encryption/maybe-encrypt- (json/encode {:secret "s3"})))]- (migrate!)- (testing "encrypted confirmed row gets the column"- (is (some? (t2/select-one-fn :confirmed_at :auth_identity :id enc-confirmed))))- (testing "legacy plaintext confirmed row gets the column"- (is (some? (t2/select-one-fn :confirmed_at :auth_identity :id plain-confirmed))))- (testing "pending (unconfirmed) enrollment stays null"- (is (nil? (t2/select-one-fn :confirmed_at :auth_identity :id pending)))))))))-(deftest backfill-transform-target-tables-test(testing "v60.2026-03-07T00:00:04 : backfill transform target tables"(impl/test-migrations ["v60.2026-03-07T00:00:04"] [migrate!]@@ -3015,6 +2987,34 @@(is (= "computed" (:data_authority provisional)))(is (= "New Target Table" (:display_name provisional)))))))))+(deftest backfill-mfa-confirmed-at-test+ (testing "v63.2026-07-10T22:29:17: confirmed_at is lifted out of the credentials JSON into the column"+ (encryption-test/with-secret-key "backfill-mfa-test-key-1234"+ (impl/test-migrations ["v63.2026-07-10T22:29:17"] [migrate!]+ (let [confirmed-at "2026-07-01T12:00:00Z"+ insert-identity!+ (fn [user-id credentials-str]+ (t2/insert-returning-pk! :auth_identity {:user_id user-id+ :provider "totp"+ :credentials credentials-str+ :created_at :%now+ :updated_at :%now}))+ enc-confirmed (insert-identity! (:id (new-instance-with-default :core_user))+ (encryption/maybe-encrypt+ (json/encode {:secret "s1" :confirmed_at confirmed-at})))+ plain-confirmed (insert-identity! (:id (new-instance-with-default :core_user))+ (json/encode {:secret "s2" :confirmed_at confirmed-at}))+ pending (insert-identity! (:id (new-instance-with-default :core_user))+ (encryption/maybe-encrypt+ (json/encode {:secret "s3"})))]+ (migrate!)+ (testing "encrypted confirmed row gets the column"+ (is (some? (t2/select-one-fn :confirmed_at :auth_identity :id enc-confirmed))))+ (testing "legacy plaintext confirmed row gets the column"+ (is (some? (t2/select-one-fn :confirmed_at :auth_identity :id plain-confirmed))))+ (testing "pending (unconfirmed) enrollment stays null"+ (is (nil? (t2/select-one-fn :confirmed_at :auth_identity :id pending)))))))))+(deftest retire-mcp-v1-oauth-scopes-test(testing (str "v64.2026-09-09T12:00:00/01: a client connected to a shipped v0.60–v0.63 release holds a 17-scope ""registration snapshot and tokens scoped to it. The v2 surface gates on six coarse scopes that no "diff --git a/test/metabase/app_db/schema_migrations_test.clj b/test/metabase/app_db/schema_migrations_test.cljindex 7b8f8834161..7838b9b0490 100644--- a/test/metabase/app_db/schema_migrations_test.clj+++ b/test/metabase/app_db/schema_migrations_test.clj@@ -3288,6 +3288,38 @@(is (some? (t2/select-one-fn :id :data_permissions :id normal-perm)))(is (= 1 (t2/count :data_permissions :db_id normal-id))))))))+(deftest auth-identity-confirmed-at-retires-misnumbered-v59-ids-test+ (testing "v63.2026-07-10 confirmed_at changesets adopt a database that ran them under their old v59 ids, and roll back"+ (impl/test-migrations ["v63.2026-07-10T22:29:15" "v63.2026-07-10T22:29:17"] [migrate!]+ (let [clog (keyword (liquibase/changelog-table-name (mdb/data-source)))+ last-order (:orderexecuted (t2/select-one clog {:order-by [[:orderexecuted :desc]]}))+ v59-ids ["v59.2026-07-10T22:29:16" "v59.2026-07-10T22:29:17"]+ column? #(seq (t2/query [(str "SELECT column_name FROM information_schema.columns"+ " WHERE lower(table_name) = 'auth_identity' AND lower(column_name) = 'confirmed_at'"+ (case (mdb/db-type)+ :mysql " AND table_schema = database()"+ :postgres " AND table_schema = current_schema()"+ :h2 ""))]))]+ ;; simulate an instance upgraded by the code that shipped these changesets under v59 ids+ (t2/query ["ALTER TABLE auth_identity ADD COLUMN confirmed_at TIMESTAMP NULL"])+ (t2/insert! clog (map-indexed (fn [i id]+ {:id id+ :author "escherize"+ :filename "migrations/059_update_migrations.yaml"+ :dateexecuted :%now+ :orderexecuted (+ last-order i 1)+ :exectype "EXECUTED"})+ v59-ids))+ (.resetAll (liquibase.changelog.ChangeLogHistoryServiceFactory/getInstance))+ (migrate!)+ (testing "the stale v59 rows are gone and the existing column is adopted"+ (is (empty? (t2/select clog :id [:in v59-ids])))+ (is (= "MARK_RAN" (t2/select-one-fn :exectype clog :id "v63.2026-07-10T22:29:16")))+ (is (column?)))+ (testing "rolling back to 62 drops the column"+ (migrate! :down 62)+ (is (not (column?))))))))+(deftest move-metabot-conversation-state-to-messages-test(testing "v64.2026-07-06: the legacy conversation state blob moves to the earliest live assistant message, then the column drops"(impl/test-migrations ["v64.2026-07-06T00:00:01" "v64.2026-07-06T00:00:02"] [migrate!]