| 1 | -- Generated by rastrillo migration generate; DO NOT EDIT. |
| 2 | -- The schema every migration in this directory adds up to. |
| 3 | |
| 4 | CREATE TRIGGER cards_are_not_hard_deleted |
| 5 | BEFORE DELETE ON cards |
| 6 | BEGIN |
| 7 | SELECT RAISE(ABORT, 'cards are not deleted: set gone, which is what DeleteCard does'); |
| 8 | END; |
| 9 | |
| 10 | CREATE TRIGGER entries_are_immutable |
| 11 | BEFORE UPDATE ON entries |
| 12 | BEGIN |
| 13 | SELECT RAISE(ABORT, 'entries are immutable: write a new entry that supersedes this one'); |
| 14 | END; |
| 15 | |
| 16 | CREATE TRIGGER entries_are_not_deleted |
| 17 | BEFORE DELETE ON entries |
| 18 | WHEN (SELECT COUNT(*) FROM cards WHERE cards.id = OLD.card_id) > 0 |
| 19 | BEGIN |
| 20 | SELECT RAISE(ABORT, 'entries are not deleted: mark the card gone instead'); |
| 21 | END; |
| 22 | |
| 23 | CREATE TRIGGER entry_values_are_immutable |
| 24 | BEFORE UPDATE ON entry_values |
| 25 | BEGIN |
| 26 | SELECT RAISE(ABORT, 'entry values are immutable: write a new entry that supersedes this one'); |
| 27 | END; |
| 28 | |
| 29 | CREATE TABLE `card_types` (`id` integer PRIMARY KEY AUTOINCREMENT,`key` text,`scope` text NOT NULL,`sealed_label` blob,`created_at` datetime,`updated_at` datetime, `sealed_plural` blob, `face_keys` text); |
| 30 | |
| 31 | CREATE TABLE `card_values` (`card_id` integer,`field_def_id` integer,`sealed_value` blob,`print` text,PRIMARY KEY (`card_id`,`field_def_id`),CONSTRAINT `fk_cards_values` FOREIGN KEY (`card_id`) REFERENCES `cards`(`id`) ON DELETE CASCADE); |
| 32 | |
| 33 | CREATE TABLE `cards` (`id` integer PRIMARY KEY AUTOINCREMENT,`card_type_id` integer NOT NULL,`revision` integer NOT NULL DEFAULT 1,`gone` numeric NOT NULL DEFAULT false,`offered` numeric NOT NULL DEFAULT false,`owner_id` integer,`created_at` datetime,`updated_at` datetime, `nonce` integer NOT NULL DEFAULT 0,CONSTRAINT `fk_cards_owner` FOREIGN KEY (`owner_id`) REFERENCES `members`(`id`) ON DELETE RESTRICT); |
| 34 | |
| 35 | CREATE TABLE `entries` (`id` integer PRIMARY KEY AUTOINCREMENT,`card_id` integer NOT NULL,`kind` text NOT NULL,`source` text,`actor_id` integer,`type_id` integer NOT NULL,`created_at` datetime,CONSTRAINT `fk_entries_actor` FOREIGN KEY (`actor_id`) REFERENCES `members`(`id`) ON DELETE RESTRICT,CONSTRAINT `fk_cards_entries` FOREIGN KEY (`card_id`) REFERENCES `cards`(`id`) ON DELETE CASCADE); |
| 36 | |
| 37 | CREATE TABLE `entry_values` (`entry_id` integer,`field_def_id` integer,`sealed_value` blob,`print` text,PRIMARY KEY (`entry_id`,`field_def_id`),CONSTRAINT `fk_entries_values` FOREIGN KEY (`entry_id`) REFERENCES `entries`(`id`) ON DELETE CASCADE); |
| 38 | |
| 39 | CREATE TABLE `events` (`id` integer PRIMARY KEY AUTOINCREMENT,`kind` text NOT NULL,`object_kind` text NOT NULL,`object_id` integer,`actor_id` integer,`actor_reason` text,`child_id` integer,`revision` integer,`changed_fields` text,`payload_sealed` blob,`payload_erased_at` datetime,`trigger_id` integer,`created_at` datetime, `nonce` integer NOT NULL DEFAULT 0); |
| 40 | |
| 41 | CREATE TABLE `field_defs` (`id` integer PRIMARY KEY AUTOINCREMENT,`card_type_id` integer NOT NULL,`key` text,`sealed_label` blob,`sealed_options` blob,`kind` text,`tier` text,`ordinal` integer,`created_at` datetime,`updated_at` datetime,CONSTRAINT `fk_card_types_fields` FOREIGN KEY (`card_type_id`) REFERENCES `card_types`(`id`) ON DELETE RESTRICT); |
| 42 | |
| 43 | CREATE TABLE `members` (`id` integer PRIMARY KEY AUTOINCREMENT,`address_print` text,`sealed_address` blob,`created_at` datetime,`updated_at` datetime); |
| 44 | |
| 45 | CREATE TABLE `refs` (`id` integer PRIMARY KEY AUTOINCREMENT,`card_id` integer NOT NULL,`entry_id` integer,`sealed_target` blob,`print` text,`created_at` datetime,CONSTRAINT `fk_cards_refs` FOREIGN KEY (`card_id`) REFERENCES `cards`(`id`) ON DELETE CASCADE,CONSTRAINT `fk_entries_refs` FOREIGN KEY (`entry_id`) REFERENCES `entries`(`id`) ON DELETE CASCADE); |
| 46 | |
| 47 | CREATE UNIQUE INDEX `idx_card_types_key` ON `card_types`(`key`); |
| 48 | |
| 49 | CREATE INDEX `idx_card_types_scope` ON `card_types`(`scope`); |
| 50 | |
| 51 | CREATE INDEX `idx_card_values_print` ON `card_values`(`print`); |
| 52 | |
| 53 | CREATE INDEX `idx_cards_card_type_id` ON `cards`(`card_type_id`); |
| 54 | |
| 55 | CREATE INDEX `idx_cards_gone` ON `cards`(`gone`); |
| 56 | |
| 57 | CREATE INDEX `idx_cards_offered` ON `cards`(`offered`); |
| 58 | |
| 59 | CREATE INDEX `idx_cards_owner_id` ON `cards`(`owner_id`); |
| 60 | |
| 61 | CREATE INDEX `idx_cards_updated_at` ON `cards`(`updated_at`); |
| 62 | |
| 63 | CREATE INDEX `idx_entries_actor_id` ON `entries`(`actor_id`); |
| 64 | |
| 65 | CREATE INDEX `idx_entries_card_id` ON `entries`(`card_id`); |
| 66 | |
| 67 | CREATE INDEX `idx_entries_created_at` ON `entries`(`created_at`); |
| 68 | |
| 69 | CREATE INDEX `idx_entries_kind` ON `entries`(`kind`); |
| 70 | |
| 71 | CREATE INDEX `idx_entries_type_id` ON `entries`(`type_id`); |
| 72 | |
| 73 | CREATE INDEX `idx_entry_values_print` ON `entry_values`(`print`); |
| 74 | |
| 75 | CREATE INDEX `idx_events_actor_id` ON `events`(`actor_id`); |
| 76 | |
| 77 | CREATE INDEX `idx_events_created_at` ON `events`(`created_at`); |
| 78 | |
| 79 | CREATE INDEX `idx_events_kind` ON `events`(`kind`); |
| 80 | |
| 81 | CREATE INDEX `idx_events_object` ON `events`(`object_kind`,`object_id`); |
| 82 | |
| 83 | CREATE INDEX `idx_events_trigger_id` ON `events`(`trigger_id`); |
| 84 | |
| 85 | CREATE INDEX `idx_field_defs_card_type_id` ON `field_defs`(`card_type_id`); |
| 86 | |
| 87 | CREATE UNIQUE INDEX `idx_field_defs_key` ON `field_defs`(`key`); |
| 88 | |
| 89 | CREATE UNIQUE INDEX `idx_members_address_print` ON `members`(`address_print`); |
| 90 | |
| 91 | CREATE INDEX `idx_refs_card_id` ON `refs`(`card_id`); |
| 92 | |
| 93 | CREATE UNIQUE INDEX `idx_refs_card_print` ON `refs`(`print`); |
| 94 | |
| 95 | CREATE INDEX `idx_refs_entry_id` ON `refs`(`entry_id`); |
| 96 | |
| 97 | |