( table: SQLiteSchemaSquashed['tables'][keyof SQLiteSchemaSquashed['tables']], action?: 'push', )
| 8 | import { SQLiteSchemaSquashed, SQLiteSquasher } from './serializer/sqliteSchema'; |
| 9 | |
| 10 | export const prepareLibSQLRecreateTable = ( |
| 11 | table: SQLiteSchemaSquashed['tables'][keyof SQLiteSchemaSquashed['tables']], |
| 12 | action?: 'push', |
| 13 | ): (JsonRecreateTableStatement | JsonCreateIndexStatement)[] => { |
| 14 | const { name, columns, uniqueConstraints, indexes, checkConstraints } = table; |
| 15 | |
| 16 | const composites: string[][] = Object.values(table.compositePrimaryKeys).map( |
| 17 | (it) => SQLiteSquasher.unsquashPK(it), |
| 18 | ); |
| 19 | |
| 20 | const references: string[] = Object.values(table.foreignKeys); |
| 21 | const fks = references.map((it) => |
| 22 | action === 'push' ? SQLiteSquasher.unsquashPushFK(it) : SQLiteSquasher.unsquashFK(it) |
| 23 | ); |
| 24 | |
| 25 | const statements: (JsonRecreateTableStatement | JsonCreateIndexStatement)[] = [ |
| 26 | { |
| 27 | type: 'recreate_table', |
| 28 | tableName: name, |
| 29 | columns: Object.values(columns), |
| 30 | compositePKs: composites, |
| 31 | referenceData: fks, |
| 32 | uniqueConstraints: Object.values(uniqueConstraints), |
| 33 | checkConstraints: Object.values(checkConstraints), |
| 34 | }, |
| 35 | ]; |
| 36 | |
| 37 | if (Object.keys(indexes).length) { |
| 38 | statements.push(...prepareCreateIndexesJson(name, '', indexes)); |
| 39 | } |
| 40 | return statements; |
| 41 | }; |
| 42 | |
| 43 | export const prepareSQLiteRecreateTable = ( |
| 44 | table: SQLiteSchemaSquashed['tables'][keyof SQLiteSchemaSquashed['tables']], |
no test coverage detected