Files
relspecgo/tests/dbtest/init/mysql.sql
T

22 lines
788 B
SQL

-- Minimal MySQL fixture for relspec container tests.
-- Extend when a MySQL reader/writer is added.
CREATE TABLE users (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
UNIQUE KEY uq_users_email (email)
) ENGINE=InnoDB;
CREATE TABLE posts (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
user_id BIGINT UNSIGNED NOT NULL,
title VARCHAR(255) NOT NULL,
body TEXT NULL,
KEY idx_posts_user (user_id),
CONSTRAINT fk_posts_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE
) ENGINE=InnoDB;
CREATE VIEW v_user_posts AS
SELECT u.id AS user_id, u.email, p.id AS post_id, p.title
FROM users u JOIN posts p ON p.user_id = u.id;