()
| 192 | }; |
| 193 | |
| 194 | const prepareFkConflict = () => { |
| 195 | const database1 = new DatabaseSync(':memory:'); |
| 196 | const database2 = new DatabaseSync(':memory:'); |
| 197 | |
| 198 | database1.exec(createDataTableSql); |
| 199 | database2.exec(createDataTableSql); |
| 200 | const fkTableSql = `CREATE TABLE other ( |
| 201 | key INTEGER PRIMARY KEY, |
| 202 | ref REFERENCES data(key) |
| 203 | )`; |
| 204 | database1.exec(fkTableSql); |
| 205 | database2.exec(fkTableSql); |
| 206 | |
| 207 | const insertDataSql = 'INSERT INTO data (key, value) VALUES (?, ?)'; |
| 208 | const insertOtherSql = 'INSERT INTO other (key, ref) VALUES (?, ?)'; |
| 209 | database1.prepare(insertDataSql).run(1, 'hello'); |
| 210 | database2.prepare(insertDataSql).run(1, 'hello'); |
| 211 | database1.prepare(insertOtherSql).run(1, 1); |
| 212 | database2.prepare(insertOtherSql).run(1, 1); |
| 213 | |
| 214 | database1.exec('DELETE FROM other WHERE key = 1'); // So we don't get a fk violation in database1 |
| 215 | const session = database1.createSession(); |
| 216 | database1.prepare('DELETE FROM data WHERE key = 1').run(); // Changeset with fk violation |
| 217 | database2.exec('PRAGMA foreign_keys = ON'); // Needs to be supported, otherwise will fail here |
| 218 | |
| 219 | return { |
| 220 | database2, |
| 221 | changeset: session.changeset() |
| 222 | }; |
| 223 | }; |
| 224 | |
| 225 | const prepareConstraintConflict = () => { |
| 226 | const database1 = new DatabaseSync(':memory:'); |
no test coverage detected