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
Fix inconsistent db defaults for data_layer / data_authority (#75689)
Chris Truter92c67e8c621e
diff --git a/resources/migrations/063/20260610_table_curation_column_defaults.yaml b/resources/migrations/063/20260610_table_curation_column_defaults.yamlnew file mode 100644index 00000000000..74d4caad437--- /dev/null+++ b/resources/migrations/063/20260610_table_curation_column_defaults.yaml@@ -0,0 +1,25 @@+## Assert DB-level defaults for metabase_table.data_layer / data_authority so they're consistent across+## app DBs (data_authority was NULL on MySQL/MariaDB). The model before-insert sets both for model inserts.++databaseChangeLog:+ - changeSet:+ id: v63.2026-06-10T10:00:00+ author: chris+ comment: Default metabase_table.data_layer to "internal" at the DB level+ changes:+ - addDefaultValue:+ tableName: metabase_table+ columnName: data_layer+ columnDataType: varchar(254)+ defaultValue: internal++ - changeSet:+ id: v63.2026-06-10T10:00:01+ author: chris+ comment: Reassert metabase_table.data_authority DB default of "unconfigured" (was inconsistent on MySQL/MariaDB)+ changes:+ - addDefaultValue:+ tableName: metabase_table+ columnName: data_authority+ columnDataType: varchar(20)+ defaultValue: unconfigureddiff --git a/src/metabase/warehouse_schema/models/table.clj b/src/metabase/warehouse_schema/models/table.cljindex bc50e76d62b..ae65b37c213 100644--- a/src/metabase/warehouse_schema/models/table.clj+++ b/src/metabase/warehouse_schema/models/table.clj@@ -172,9 +172,12 @@(t2/define-before-insert :model/Table[table]- (let [defaults {:display_name (humanization/name->human-readable-name (:name table))- :field_order (driver/default-field-order (t2/select-one-fn :engine :model/Database :id (:db_id table)))- :data_layer :internal}]+ ;; Default both curation columns here so model inserts are consistent across app DBs; a migration+ ;; reasserts matching DB-level defaults for non-model insert paths.+ (let [defaults {:display_name (humanization/name->human-readable-name (:name table))+ :field_order (driver/default-field-order (t2/select-one-fn :engine :model/Database :id (:db_id table)))+ :data_layer :internal+ :data_authority :unconfigured}](collection/check-allowed-content :table (:collection_id table))(merge defaults table)))diff --git a/test/metabase/warehouse_schema/models/table_test.clj b/test/metabase/warehouse_schema/models/table_test.cljindex cbcabc0503e..1d81f1fbeee 100644--- a/test/metabase/warehouse_schema/models/table_test.clj+++ b/test/metabase/warehouse_schema/models/table_test.clj@@ -743,3 +743,23 @@(serdes/load-one! ingested table)(is (= (keyword expected)(t2/select-one-fn :data_layer :model/Table :id table-id))))))))))++(deftest curation-column-defaults-test+ (testing "a new table gets consistent non-null data_layer and data_authority defaults"+ (testing "via the model before-insert (the path sync uses)"+ (mt/with-temp [:model/Database {db-id :id} {}+ :model/Table {table-id :id} {:db_id db-id}]+ (is (=? {:data_layer :internal :data_authority :unconfigured}+ (t2/select-one [:model/Table :data_layer :data_authority] :id table-id)))))+ (testing "via the DB-level column default when before-insert is bypassed (raw insert)"+ ;; Exercises the non-model insert path, guarding the migration that asserts the DB-level defaults.+ (mt/with-temp [:model/Database {db-id :id} {}]+ (t2/query-one {:insert-into :metabase_table+ :values [{:name "raw-insert-probe"+ :db_id db-id+ :active true+ :created_at :%now+ :updated_at :%now}]})+ (is (=? {:data_layer :internal :data_authority :unconfigured}+ (t2/select-one [:model/Table :data_layer :data_authority]+ :name "raw-insert-probe" :db_id db-id)))))))