Creating migrations files to create movies table and add movies check constraints. Updating API version number. Updating README.md adding 'SQL Migrations' section. Updating deployment file to make migrations before building API. Adding some .idea files into .gitignore.
Some checks failed
Deploy Greenlight API / deploy (push) Failing after 40s
Some checks failed
Deploy Greenlight API / deploy (push) Failing after 40s
This commit is contained in:
1
migrations/000001_create_movies_table.down.sql
Normal file
1
migrations/000001_create_movies_table.down.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE IF EXISTS movies;
|
||||
9
migrations/000001_create_movies_table.up.sql
Normal file
9
migrations/000001_create_movies_table.up.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE IF NOT EXISTS movies (
|
||||
id bigserial PRIMARY KEY,
|
||||
created_at timestamp(0) with time zone NOT NULL DEFAULT NOW(),
|
||||
title text NOT NULL,
|
||||
year integer NOT NULL,
|
||||
runtime integer NOT NULL,
|
||||
genres text[] NOT NULL,
|
||||
version integer NOT NULL DEFAULT 1
|
||||
);
|
||||
3
migrations/000002_add_movies_check_constraints.down.sql
Normal file
3
migrations/000002_add_movies_check_constraints.down.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE movies DROP CONSTRAINT IF EXISTS movies_runtime_check;
|
||||
ALTER TABLE movies DROP CONSTRAINT IF EXISTS movies_year_check;
|
||||
ALTER TABLE movies DROP CONSTRAINT IF EXISTS genres_length_check;
|
||||
5
migrations/000002_add_movies_check_constraints.up.sql
Normal file
5
migrations/000002_add_movies_check_constraints.up.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE movies ADD CONSTRAINT movies_runtime_check CHECK (runtime >= 0);
|
||||
|
||||
ALTER TABLE movies ADD CONSTRAINT movies_year_check CHECK (year BETWEEN 1888 AND date_part('year', now()));
|
||||
|
||||
ALTER TABLE movies ADD CONSTRAINT genres_length_check CHECK (array_length(genres, 1) BETWEEN 1 AND 5);
|
||||
Reference in New Issue
Block a user