Skip to content

Commit

Permalink
simplify and rename pg spec migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
fridgerator committed Nov 11, 2017
1 parent 1d94fa8 commit b4514ea
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 241 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -13,7 +13,7 @@ before_script:
- mysql -e 'create database crecto_test'
- mysql -Dcrecto_test < spec/migrations/mysql_migrations.sql
- psql -c 'create database crecto_test;' -U postgres
- psql $PG_URL < spec/migrations/pg_users.sql
- psql $PG_URL < spec/migrations/pg_migrations.sql
- sqlite3 ./crecto_test.db < spec/migrations/sqlite3_migrations.sql
- if [ ! -z "$PG_URL" ]; then cp ./spec/travis_pg_repo.cr ./spec/repo.cr; fi
- if [ ! -z "$MYSQL_URL" ]; then cp ./spec/travis_mysql_repo.cr ./spec/repo.cr; fi
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -9,7 +9,7 @@ migrate:
ifndef PG_URL
$(error PG_URL is undefined)
else
psql -q $(PG_URL) < ./spec/migrations/pg_users.sql
psql -q $(PG_URL) < ./spec/migrations/pg_migrations.sql
endif

spec:
Expand Down
112 changes: 112 additions & 0 deletions spec/migrations/pg_migrations.sql
@@ -0,0 +1,112 @@
BEGIN;
DROP TABLE IF EXISTS user_projects;
DROP TABLE IF EXISTS addresses;
DROP TABLE IF EXISTS posts;
DROP TABLE IF EXISTS users;
DROP TABLE IF EXISTS users_different_defaults;
DROP INDEX IF EXISTS users_4asdf;
DROP TABLE IF EXISTS users_large_defaults;
DROP TABLE IF EXISTS projects;
DROP TABLE IF EXISTS users_json;
DROP TABLE IF EXISTS things;
DROP TABLE IF EXISTS users_uuid;
DROP TABLE IF EXISTS vehicles;

CREATE TABLE users(
id BIGSERIAL PRIMARY KEY,
name character varying NOT NULL,
smallnum smallint,
things integer,
stuff integer,
nope float,
yep bool,
pageviews bigint,
some_date timestamp without time zone,
created_at timestamp without time zone,
updated_at timestamp without time zone,
unique_field character varying UNIQUE
);

CREATE TABLE users_different_defaults(
user_id BIGSERIAL PRIMARY KEY,
name character varying NOT NULL,
xyz timestamp without time zone
);

CREATE TABLE users_large_defaults(
id BIGINT PRIMARY KEY,
name character varying NOT NULL
);

CREATE SEQUENCE users_large_defaults_id_seq
START WITH 1121
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;

ALTER SEQUENCE users_large_defaults_id_seq OWNED BY users_large_defaults.id;
ALTER TABLE ONLY users_large_defaults ALTER COLUMN id SET DEFAULT nextval('users_large_defaults_id_seq'::regclass);
CREATE UNIQUE INDEX users_4asdf ON users_large_defaults (id);


CREATE TABLE posts(
id BIGSERIAL PRIMARY KEY,
user_id INTEGER references users(id),
created_at timestamp without time zone,
updated_at timestamp without time zone
);

CREATE TABLE addresses(
id BIGSERIAL PRIMARY KEY,
user_id INTEGER references users(id),
created_at timestamp without time zone,
updated_at timestamp without time zone
);

CREATE TABLE projects(
id BIGSERIAL PRIMARY KEY,
name VARCHAR(255),
created_at timestamp without time zone,
updated_at timestamp without time zone
);


CREATE TABLE user_projects(
user_id INTEGER,
project_id INTEGER references projects(id),
created_at timestamp without time zone,
updated_at timestamp without time zone
);

CREATE TABLE users_json(
id BIGSERIAL PRIMARY KEY,
settings jsonb,
created_at timestamp without time zone,
updated_at timestamp without time zone
);

CREATE TABLE things(
id BIGSERIAL PRIMARY KEY,
user_different_defaults_id INTEGER references users_different_defaults(user_id),
created_at timestamp without time zone,
updated_at timestamp without time zone
);

CREATE TABLE users_uuid(
uuid character varying NOT NULL,
name character varying,
created_at timestamp without time zone,
updated_at timestamp without time zone
);


CREATE TABLE vehicles(
id BIGSERIAL PRIMARY KEY,
state_string character varying NOT NULL,
vehicle_type INTEGER NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone
);

COMMIT;
235 changes: 0 additions & 235 deletions spec/migrations/pg_users.sql

This file was deleted.

0 comments on commit b4514ea

Please sign in to comment.