fix: title_messages schema to fix on conflict insertion
This commit is contained in:
32
drizzle/0007_warm_alex_wilder.sql
Normal file
32
drizzle/0007_warm_alex_wilder.sql
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
You're trying to delete PRIMARY KEY(message_id,title_id) from 'title_messages' table
|
||||||
|
SQLite does not supportprimary key deletion from existing table
|
||||||
|
You can do it in 3 steps with drizzle orm:
|
||||||
|
- create new mirror table table without pk, rename current table to old_table, generate SQL
|
||||||
|
- migrate old data from one table to another
|
||||||
|
- delete old_table in schema, generate sql
|
||||||
|
|
||||||
|
or create manual migration like below:
|
||||||
|
|
||||||
|
ALTER TABLE table_name RENAME TO old_table;
|
||||||
|
CREATE TABLE table_name (
|
||||||
|
column1 datatype [ NULL | NOT NULL ],
|
||||||
|
column2 datatype [ NULL | NOT NULL ],
|
||||||
|
...
|
||||||
|
PRIMARY KEY (pk_col1, pk_col2, ... pk_col_n)
|
||||||
|
);
|
||||||
|
INSERT INTO table_name SELECT * FROM old_table;
|
||||||
|
|
||||||
|
Due to that we don't generate migration automatically and it has to be done manually
|
||||||
|
*/
|
||||||
|
ALTER TABLE title_messages RENAME TO _title_messages;
|
||||||
|
--> statement-breakpoint
|
||||||
|
CREATE TABLE title_messages (
|
||||||
|
title_id integer NOT NULL,
|
||||||
|
message_id text NOT NULL,
|
||||||
|
PRIMARY KEY (title_id)
|
||||||
|
);
|
||||||
|
--> statement-breakpoint
|
||||||
|
INSERT INTO title_messages SELECT * FROM _title_messages;
|
||||||
|
--> statement-breakpoint
|
||||||
|
DROP TABLE _title_messages;
|
||||||
145
drizzle/meta/0007_snapshot.json
Normal file
145
drizzle/meta/0007_snapshot.json
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
{
|
||||||
|
"version": "6",
|
||||||
|
"dialect": "sqlite",
|
||||||
|
"id": "9b7fe2b7-e3b1-4557-98b6-ba02f15eb37c",
|
||||||
|
"prevId": "779bdeb8-3d3b-4429-8260-2ef628d0baa0",
|
||||||
|
"tables": {
|
||||||
|
"device_tokens": {
|
||||||
|
"name": "device_tokens",
|
||||||
|
"columns": {
|
||||||
|
"device_id": {
|
||||||
|
"name": "device_id",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"token": {
|
||||||
|
"name": "token",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"username": {
|
||||||
|
"name": "username",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"last_connected_at": {
|
||||||
|
"name": "last_connected_at",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": false,
|
||||||
|
"autoincrement": false,
|
||||||
|
"default": "(CURRENT_TIMESTAMP)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {
|
||||||
|
"device_tokens_token_unique": {
|
||||||
|
"name": "device_tokens_token_unique",
|
||||||
|
"columns": ["token"],
|
||||||
|
"isUnique": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {}
|
||||||
|
},
|
||||||
|
"key_value": {
|
||||||
|
"name": "key_value",
|
||||||
|
"columns": {
|
||||||
|
"key": {
|
||||||
|
"name": "key",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"name": "value",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {}
|
||||||
|
},
|
||||||
|
"title_messages": {
|
||||||
|
"name": "title_messages",
|
||||||
|
"columns": {
|
||||||
|
"title_id": {
|
||||||
|
"name": "title_id",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": true,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"message_id": {
|
||||||
|
"name": "message_id",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {},
|
||||||
|
"foreignKeys": {},
|
||||||
|
"compositePrimaryKeys": {},
|
||||||
|
"uniqueConstraints": {}
|
||||||
|
},
|
||||||
|
"watch_status": {
|
||||||
|
"name": "watch_status",
|
||||||
|
"columns": {
|
||||||
|
"device_id": {
|
||||||
|
"name": "device_id",
|
||||||
|
"type": "text",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
},
|
||||||
|
"title_id": {
|
||||||
|
"name": "title_id",
|
||||||
|
"type": "integer",
|
||||||
|
"primaryKey": false,
|
||||||
|
"notNull": true,
|
||||||
|
"autoincrement": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"indexes": {},
|
||||||
|
"foreignKeys": {
|
||||||
|
"watch_status_device_id_device_tokens_device_id_fk": {
|
||||||
|
"name": "watch_status_device_id_device_tokens_device_id_fk",
|
||||||
|
"tableFrom": "watch_status",
|
||||||
|
"tableTo": "device_tokens",
|
||||||
|
"columnsFrom": ["device_id"],
|
||||||
|
"columnsTo": ["device_id"],
|
||||||
|
"onDelete": "no action",
|
||||||
|
"onUpdate": "no action"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"compositePrimaryKeys": {
|
||||||
|
"watch_status_device_id_title_id_pk": {
|
||||||
|
"columns": ["device_id", "title_id"],
|
||||||
|
"name": "watch_status_device_id_title_id_pk"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"uniqueConstraints": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"enums": {},
|
||||||
|
"_meta": {
|
||||||
|
"schemas": {},
|
||||||
|
"tables": {},
|
||||||
|
"columns": {}
|
||||||
|
},
|
||||||
|
"internal": {
|
||||||
|
"indexes": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,6 +50,13 @@
|
|||||||
"when": 1725836922065,
|
"when": 1725836922065,
|
||||||
"tag": "0006_sticky_donald_blake",
|
"tag": "0006_sticky_donald_blake",
|
||||||
"breakpoints": true
|
"breakpoints": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idx": 7,
|
||||||
|
"version": "6",
|
||||||
|
"when": 1726019943934,
|
||||||
|
"tag": "0007_warm_alex_wilder",
|
||||||
|
"breakpoints": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,16 +34,10 @@ export const keyValueTable = sqliteTable("key_value", {
|
|||||||
value: text("value").notNull(),
|
value: text("value").notNull(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const titleMessagesTable = sqliteTable(
|
export const titleMessagesTable = sqliteTable("title_messages", {
|
||||||
"title_messages",
|
titleId: integer("title_id").notNull().primaryKey(),
|
||||||
{
|
messageId: text("message_id").notNull(),
|
||||||
titleId: integer("title_id").notNull(),
|
});
|
||||||
messageId: text("message_id").notNull(),
|
|
||||||
},
|
|
||||||
(table) => ({
|
|
||||||
pk: primaryKey({ columns: [table.titleId, table.messageId] }),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
export const tables = [
|
export const tables = [
|
||||||
watchStatusTable,
|
watchStatusTable,
|
||||||
|
|||||||
Reference in New Issue
Block a user