From 8aaab7465dbd6bfad9ace6942845cf1cacb39a7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Galeran?= Date: Thu, 21 Mar 2024 14:46:25 +0100 Subject: [PATCH] feat(migrate/sqlite): ignore Cloudflare D1 specific tables (#4782) --- .../sql-schema-describer/src/sqlite.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/schema-engine/sql-schema-describer/src/sqlite.rs b/schema-engine/sql-schema-describer/src/sqlite.rs index 1f28958605a2..51f75a90343a 100644 --- a/schema-engine/sql-schema-describer/src/sqlite.rs +++ b/schema-engine/sql-schema-describer/src/sqlite.rs @@ -162,7 +162,7 @@ impl<'a> SqlSchemaDescriber<'a> { (name, r#type, definition) }) - .filter(|(table_name, _, _)| !is_system_table(table_name)); + .filter(|(table_name, _, _)| !is_table_ignored(table_name)); let mut map = IndexMap::default(); @@ -603,18 +603,22 @@ fn unquote_sqlite_string_default(s: &str) -> Cow<'_, str> { } } -/// Returns whether a table is one of the SQLite system tables. -fn is_system_table(table_name: &str) -> bool { - SQLITE_SYSTEM_TABLES - .iter() - .any(|system_table| table_name == *system_table) +/// Returns whether a table is one of the SQLite system tables or a Cloudflare D1 specific table. +fn is_table_ignored(table_name: &str) -> bool { + SQLITE_IGNORED_TABLES.iter().any(|table| table_name == *table) } /// See https://www.sqlite.org/fileformat2.html -const SQLITE_SYSTEM_TABLES: &[&str] = &[ +/// + Cloudflare D1 specific tables +const SQLITE_IGNORED_TABLES: &[&str] = &[ + // SQLite system tables "sqlite_sequence", "sqlite_stat1", "sqlite_stat2", "sqlite_stat3", "sqlite_stat4", + // Cloudflare D1 specific tables + "_cf_KV", + // This is the default but can be configured by the user + "d1_migrations", ];