21 lines
883 B
SQL
21 lines
883 B
SQL
CREATE TABLE recordings (
|
|
id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
description VARCHAR(200) NOT NULL,
|
|
public BOOLEAN NOT NULL DEFAULT true,
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
);
|
|
|
|
CREATE TABLE musicians_recordings (
|
|
user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
|
recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE
|
|
);
|
|
|
|
ALTER TABLE musicians_recordings ADD CONSTRAINT musician_recording_uniqkey UNIQUE (user_id, recording_id);
|
|
|
|
CREATE TABLE bands_recordings (
|
|
band_id VARCHAR(64) NOT NULL REFERENCES bands(id) ON DELETE CASCADE,
|
|
recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE
|
|
);
|
|
|
|
ALTER TABLE bands_recordings ADD CONSTRAINT band_recording_uniqkey UNIQUE (band_id, recording_id); |