-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
338 additions
and
66 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
package models | ||
|
||
import "time" | ||
|
||
type Movie struct { | ||
ID int `gorm:"primary_key"` | ||
Title string `gorm:"type:varchar(150);not null"` | ||
Description string `gorm:"type:varchar(1000)"` | ||
ReleaseDate time.Time | ||
ReleaseDate string | ||
Rating float64 `gorm:"type:decimal(2,1)"` | ||
Actors []*Actor `gorm:"many2many:actor_movies;foreignKey:ID;joinForeignKey:MovieID;References:ID;joinReferences:ActorID"` | ||
Actors []*Actor `gorm:"many2many:actormovies;"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
DROP SCHEMA IF EXISTS vk CASCADE; | ||
DROP TABLE IF EXISTS vk.actors; | ||
DROP TABLE IF EXISTS vk.movies; | ||
DROP TABLE IF EXISTS vk.actor_movie; | ||
|
||
CREATE SCHEMA IF NOT EXISTS vk; | ||
|
||
CREATE TABLE vk.actors ( | ||
actor_id SERIAL PRIMARY KEY, | ||
id SERIAL PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
gender CHAR(1), | ||
date_of_birth DATE, | ||
CHECK (gender IN ('M', 'F')) | ||
); | ||
|
||
CREATE TABLE vk.movies ( | ||
movie_id SERIAL PRIMARY KEY, | ||
title VARCHAR(150) NOT NULL CHECK (LENGTH(title) >= 1 AND LENGTH(title) <= 150), | ||
id SERIAL PRIMARY KEY, | ||
title VARCHAR(150) NOT NULL CHECK ( | ||
LENGTH(title) >= 1 | ||
AND LENGTH(title) <= 150 | ||
), | ||
description VARCHAR(1000), | ||
release_date DATE, | ||
rating DECIMAL(2, 1) CHECK (rating >= 1 AND rating <= 10) | ||
); | ||
|
||
CREATE TABLE vk.actor_movie ( | ||
actor_id INT NOT NULL, | ||
movie_id INT NOT NULL, | ||
PRIMARY KEY (actor_id, movie_id), | ||
FOREIGN KEY (actor_id) REFERENCES vk.actors (actor_id) ON DELETE CASCADE, | ||
FOREIGN KEY (movie_id) REFERENCES vk.movies (movie_id) ON DELETE CASCADE | ||
rating DECIMAL(2, 1) CHECK ( | ||
rating >= 1 | ||
AND rating <= 10 | ||
) | ||
); | ||
CREATE TABLE vk.actor_movies ( | ||
actor_name VARCHAR(255) NOT NULL, | ||
movie_title VARCHAR(150) NOT NULL, | ||
PRIMARY KEY (actor_name, movie_title), | ||
CONSTRAINT fk_actor_name FOREIGN KEY (actor_name) REFERENCES vk.actors(name) ON DELETE CASCADE, | ||
CONSTRAINT fk_movie_title FOREIGN KEY (movie_title) REFERENCES vk.movies(title) ON DELETE CASCADE | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.