Skip to content

Commit

Permalink
feat(migrate/sqlite): ignore Cloudflare D1 specific tables (#4782)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolg42 authored Mar 21, 2024
1 parent dedf0b7 commit 8aaab74
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions schema-engine/sql-schema-describer/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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",
];

0 comments on commit 8aaab74

Please sign in to comment.