This seems dumb to copy the code, but not sure there is a better solution. Two alternatives I can imagine are:
- Using CREATE TABLE AS SELECT but it has some limitations: Primary keys are NOT preserved, other constraints may be lost (UNIQUE, NOT NULL, CHECK constraints, etc.), and column types might be inferred differently in some edge cases.
- Using SQLite's schema introspection to dynamically create identical tables, but this is hacky.
Note that in each case, whenever adding a schema migration, we'll have to migrate two tables at once, so this approach gives more visibillity that there are two tables with the same schema to update
Depends on D14836