mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 17:43:23 -08:00
[Server] Deck sync identity: schema v38 + proto guid/hash fields
This commit is contained in:
parent
7fa6234eee
commit
10d46bafbd
6 changed files with 70 additions and 2 deletions
32
servatrice/migrations/servatrice_0037_to_0038.sql
Normal file
32
servatrice/migrations/servatrice_0037_to_0038.sql
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
-- Servatrice db migration from version 37 to version 38
|
||||
|
||||
-- Deck collection sync + versioning.
|
||||
--
|
||||
-- 1. Stable per-deck identity and change detection for two-way sync:
|
||||
-- guid links a local file to its server row across renames, hash detects
|
||||
-- content changes without downloading, last_modified drives newest-wins
|
||||
-- default and conflict highlighting, deleted implements tombstones so a
|
||||
-- delete on one device does not resurrect from the other.
|
||||
-- 2. Limited per-deck version history: every hash-changing upload inserts a
|
||||
-- row; the server prunes beyond the configured retention (default 20).
|
||||
|
||||
ALTER TABLE `cockatrice_decklist_files`
|
||||
ADD COLUMN `guid` char(36) NULL AFTER `tags`,
|
||||
ADD COLUMN `hash` char(40) NULL AFTER `guid`,
|
||||
ADD COLUMN `last_modified` datetime NULL AFTER `hash`,
|
||||
ADD COLUMN `deleted` tinyint(1) NOT NULL DEFAULT 0 AFTER `last_modified`;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `cockatrice_deck_versions` (
|
||||
`id` int(7) unsigned zerofill NOT NULL auto_increment,
|
||||
`deck_id` int(7) unsigned zerofill NOT NULL,
|
||||
`version_no` int(7) unsigned NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
`hash` char(40) NULL,
|
||||
`created_at` datetime NOT NULL,
|
||||
`created_by_clientid` varchar(15) NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `deck_id` (`deck_id`),
|
||||
FOREIGN KEY(`deck_id`) REFERENCES `cockatrice_decklist_files`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
UPDATE cockatrice_schema_version SET version=38 WHERE version=37;
|
||||
|
|
@ -20,7 +20,7 @@ CREATE TABLE IF NOT EXISTS `cockatrice_schema_version` (
|
|||
PRIMARY KEY (`version`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
INSERT INTO cockatrice_schema_version VALUES(37);
|
||||
INSERT INTO cockatrice_schema_version VALUES(38);
|
||||
|
||||
-- users and user data tables
|
||||
CREATE TABLE IF NOT EXISTS `cockatrice_users` (
|
||||
|
|
@ -71,11 +71,30 @@ CREATE TABLE IF NOT EXISTS `cockatrice_decklist_files` (
|
|||
`banner_card_provider` varchar(32) NULL,
|
||||
`color_identity` varchar(5) NULL,
|
||||
`tags` text NULL,
|
||||
`guid` char(36) NULL,
|
||||
`hash` char(40) NULL,
|
||||
`last_modified` datetime NULL,
|
||||
`deleted` tinyint(1) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `FolderPlusUser` (`id_folder`,`id_user`),
|
||||
FOREIGN KEY(`id_user`) REFERENCES `cockatrice_users`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- Per-deck version history for collection sync.
|
||||
-- One row per hash-changing upload; pruned beyond retention (default 20).
|
||||
CREATE TABLE IF NOT EXISTS `cockatrice_deck_versions` (
|
||||
`id` int(7) unsigned zerofill NOT NULL auto_increment,
|
||||
`deck_id` int(7) unsigned zerofill NOT NULL,
|
||||
`version_no` int(7) unsigned NOT NULL,
|
||||
`content` text NOT NULL,
|
||||
`hash` char(40) NULL,
|
||||
`created_at` datetime NOT NULL,
|
||||
`created_by_clientid` varchar(15) NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `deck_id` (`deck_id`),
|
||||
FOREIGN KEY(`deck_id`) REFERENCES `cockatrice_decklist_files`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- Temporary deck shares: a named bundle of decks that can be fetched by
|
||||
-- anyone who knows the (unguessable) token, until the share expires.
|
||||
CREATE TABLE IF NOT EXISTS `cockatrice_deck_share` (
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
class QSqlQuery;
|
||||
|
||||
#define DATABASE_SCHEMA_VERSION 37
|
||||
#define DATABASE_SCHEMA_VERSION 38
|
||||
|
||||
class Servatrice;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue