Files
Termix/plugins/termix-identity/migrations/mysql/0001_adopt_termix_identity_tables.sql
T

47 lines
2.0 KiB
SQL

-- termix-identity 0001: adopt_termix_identity_tables
-- Generated by termix-plugin migrations. Review before committing.
-- Hand-edited: keeps the legacy foreign keys the SDK cannot declare
-- (keys and ca to their identity, keys to ssh_credentials).
CREATE TABLE IF NOT EXISTS `termix_identities` (
`id` int AUTO_INCREMENT PRIMARY KEY,
`user_id` varchar(255) NOT NULL UNIQUE,
`handle` varchar(255) NOT NULL UNIQUE,
`description` text,
`created_at` text NOT NULL DEFAULT (CURRENT_TIMESTAMP),
`updated_at` text NOT NULL DEFAULT (CURRENT_TIMESTAMP),
FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
);
RENAME TABLE `termix_identities` TO `p_termix_identity_identities`;
CREATE TABLE IF NOT EXISTS `termix_identity_keys` (
`id` int AUTO_INCREMENT PRIMARY KEY,
`identity_id` int NOT NULL,
`user_id` varchar(255) NOT NULL,
`public_key` text NOT NULL,
`key_type` text NOT NULL,
`algorithm` text NOT NULL,
`label` text,
`comment` text,
`source` text NOT NULL DEFAULT ('manual'),
`credential_id` int,
`enabled` boolean NOT NULL DEFAULT true,
`created_at` text NOT NULL DEFAULT (CURRENT_TIMESTAMP),
FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
FOREIGN KEY (`identity_id`) REFERENCES `p_termix_identity_identities` (`id`) ON DELETE CASCADE,
FOREIGN KEY (`credential_id`) REFERENCES `ssh_credentials` (`id`) ON DELETE SET NULL
);
RENAME TABLE `termix_identity_keys` TO `p_termix_identity_keys`;
CREATE TABLE IF NOT EXISTS `termix_identity_ca` (
`id` int AUTO_INCREMENT PRIMARY KEY,
`identity_id` int NOT NULL UNIQUE,
`user_id` varchar(255) NOT NULL,
`public_key` text NOT NULL,
`private_key` text NOT NULL,
`validity_days` int NOT NULL DEFAULT 90,
`created_at` text NOT NULL DEFAULT (CURRENT_TIMESTAMP),
`updated_at` text NOT NULL DEFAULT (CURRENT_TIMESTAMP),
FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE,
FOREIGN KEY (`identity_id`) REFERENCES `p_termix_identity_identities` (`id`) ON DELETE CASCADE
);
RENAME TABLE `termix_identity_ca` TO `p_termix_identity_ca`;