Bluemage/schemas/migrations/20240805124501_create_devices_table.sql

33 lines
1 KiB
MySQL
Raw Normal View History

2024-08-05 23:06:32 +07:00
-- +goose Up
-- +goose StatementBegin
CREATE TABLE devices (
slug VARCHAR(255) PRIMARY KEY COLLATE NOCASE,
disabled TINYINT NOT NULL DEFAULT 0,
name TEXT NOT NULL COLLATE NOCASE,
resolution_x DOUBLE NOT NULL,
resolution_y DOUBLE NOT NULL,
aspect_ratio_tolerance DOUBLE NOT NULL DEFAULT 0.2,
min_x INTEGER NOT NULL DEFAULT 0,
min_y INTEGER NOT NULL DEFAULT 0,
max_x INTEGER NOT NULL DEFAULT 0,
max_y INTEGER NOT NULL DEFAULT 0,
nsfw TINYINT NOT NULL DEFAULT 0,
single_folder_mode TINYINT NOT NULL DEFAULT 0,
created_at BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
updated_at BIGINT NOT NULL DEFAULT (strftime('%s', 'now'))
);
CREATE UNIQUE INDEX idx_devices_unique_slug ON devices(slug);
CREATE TRIGGER devices_update_timestamp AFTER UPDATE ON devices FOR EACH ROW
BEGIN
UPDATE devices SET updated_at = strftime('%s', 'now') WHERE slug = old.slug;
END;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE devices;
-- +goose StatementEnd