rkaneko
5 years ago
commit
4626f29fb8
6 changed files with 226 additions and 0 deletions
-
1.gitignore
-
28README.md
-
12docker-compose.yml
-
6env/local/.env
-
145sql/organizations.sql
-
34sql/schema.sql
@ -0,0 +1 @@ |
|||||
|
# ignore config |
@ -0,0 +1,28 @@ |
|||||
|
SQL test |
||||
|
=== |
||||
|
|
||||
|
### Usage |
||||
|
|
||||
|
- Run up Postgresql server |
||||
|
|
||||
|
```bash |
||||
|
$ docker-compose up db |
||||
|
``` |
||||
|
|
||||
|
- Stop Postgresql server |
||||
|
|
||||
|
```bash |
||||
|
$ docker-compose down |
||||
|
``` |
||||
|
|
||||
|
- Connect to test database on Postgresql server using psql |
||||
|
|
||||
|
```bash |
||||
|
$ docker-compose exec db psql -U postgres test |
||||
|
``` |
||||
|
|
||||
|
- Execute SQL file |
||||
|
|
||||
|
```bash |
||||
|
$ docker-compose exec db psql -v ON_ERROR_STOP=1 -U postgres test -a -f "sql/schema.sql" |
||||
|
``` |
@ -0,0 +1,12 @@ |
|||||
|
version: "3.3" |
||||
|
|
||||
|
services: |
||||
|
db: |
||||
|
container_name: "sql_test_db" |
||||
|
image: "mdillon/postgis:10" |
||||
|
volumes: |
||||
|
- "./sql:/sql" |
||||
|
env_file: |
||||
|
- "env/local/.env" |
||||
|
ports: |
||||
|
- "5438:5432" |
@ -0,0 +1,6 @@ |
|||||
|
POSTGRES_USER=postgres |
||||
|
POSTGRES_PASSWORD=password |
||||
|
POSTGRES_DB=test |
||||
|
POSTGRES_HOST=postgres |
||||
|
POSTGRES_PORT=5432 |
||||
|
# POSTGIS_MAJOR=2.3 |
@ -0,0 +1,145 @@ |
|||||
|
begin; |
||||
|
|
||||
|
INSERT INTO addresses ( |
||||
|
address_line_1, |
||||
|
address_line_2, |
||||
|
city, |
||||
|
region, |
||||
|
country, |
||||
|
zip_code, |
||||
|
phone |
||||
|
) VALUES |
||||
|
( |
||||
|
'test_line_1', |
||||
|
'test_line_2', |
||||
|
'test_city', |
||||
|
'test_region', |
||||
|
'JP', |
||||
|
'103-0023', |
||||
|
'090-0000-1111' |
||||
|
) |
||||
|
,( |
||||
|
'Mars', |
||||
|
'Moon', |
||||
|
'Chuo-ku', |
||||
|
'Tokyo', |
||||
|
'JP', |
||||
|
'000-0001', |
||||
|
'090-0000-1112' |
||||
|
) |
||||
|
,( |
||||
|
'Saturn', |
||||
|
'Sun', |
||||
|
'Shinjuku-ku', |
||||
|
'Tokyo', |
||||
|
'JP', |
||||
|
'000-0002', |
||||
|
'090-0000-1113' |
||||
|
) |
||||
|
,( |
||||
|
'S', |
||||
|
'S', |
||||
|
'Shinjuku-ku', |
||||
|
'Tokyo', |
||||
|
'JP', |
||||
|
'000-0003', |
||||
|
'090-0000-1114' |
||||
|
) |
||||
|
,( |
||||
|
'A', |
||||
|
'A', |
||||
|
'Shinjuku-ku', |
||||
|
'Tokyo', |
||||
|
'JP', |
||||
|
'000-0004', |
||||
|
'090-0000-1115' |
||||
|
) |
||||
|
,( |
||||
|
'B', |
||||
|
'B', |
||||
|
'Shinjuku-ku', |
||||
|
'Tokyo', |
||||
|
'JP', |
||||
|
'000-0005', |
||||
|
'090-0000-1116' |
||||
|
) |
||||
|
,( |
||||
|
'D', |
||||
|
'D', |
||||
|
'Shinjuku-ku', |
||||
|
'Tokyo', |
||||
|
'JP', |
||||
|
'000-0005', |
||||
|
'090-0000-1116' |
||||
|
) |
||||
|
; |
||||
|
|
||||
|
INSERT INTO organizations ( |
||||
|
name, |
||||
|
address_id, |
||||
|
type |
||||
|
) VALUES |
||||
|
( |
||||
|
'Zoozle', |
||||
|
(SELECT id FROM addresses ORDER BY id ASC LIMIT 1 OFFSET 0), |
||||
|
'CUSTOMER' |
||||
|
) |
||||
|
,( |
||||
|
'Bmazon', |
||||
|
(SELECT id FROM addresses ORDER BY id ASC LIMIT 1 OFFSET 1), |
||||
|
'ENTERPRISE' |
||||
|
) |
||||
|
,( |
||||
|
'Ncrosoft', |
||||
|
(SELECT id FROM addresses ORDER BY id ASC LIMIT 1 OFFSET 2), |
||||
|
'ENTERPRISE_CUSTOMER' |
||||
|
) |
||||
|
,( |
||||
|
'Moomle', |
||||
|
(SELECT id FROM addresses ORDER BY id ASC LIMIT 1 OFFSET 3), |
||||
|
'ENTERPRISE_CUSTOMER' |
||||
|
) |
||||
|
,( |
||||
|
'Cmazon', |
||||
|
(SELECT id FROM addresses ORDER BY id ASC LIMIT 1 OFFSET 4), |
||||
|
'ENTERPRISE_CUSTOMER' |
||||
|
) |
||||
|
,( |
||||
|
'Zcrosoft', |
||||
|
(SELECT id FROM addresses ORDER BY id ASC LIMIT 1 OFFSET 5), |
||||
|
'ENTERPRISE' |
||||
|
) |
||||
|
,( |
||||
|
'Ecrosoft', |
||||
|
(SELECT id FROM addresses ORDER BY id ASC LIMIT 1 OFFSET 6), |
||||
|
'ENTERPRISE_CUSTOMER' |
||||
|
) |
||||
|
; |
||||
|
|
||||
|
INSERT INTO enterprise_sales_enterprise_customers ( |
||||
|
sales_organization_id, |
||||
|
customer_organization_id |
||||
|
) VALUES |
||||
|
( |
||||
|
(SELECT id FROM organizations WHERE name = 'Bmazon' ORDER BY id DESC LIMIT 1), |
||||
|
(SELECT id FROM organizations WHERE name = 'Ncrosoft' ORDER BY id DESC LIMIT 1) |
||||
|
) |
||||
|
,( |
||||
|
(SELECT id FROM organizations WHERE name = 'Bmazon' ORDER BY id DESC LIMIT 1), |
||||
|
(SELECT id FROM organizations WHERE name = 'Moomle' ORDER BY id DESC LIMIT 1) |
||||
|
) |
||||
|
,( |
||||
|
(SELECT id FROM organizations WHERE name = 'Bmazon' ORDER BY id DESC LIMIT 1), |
||||
|
(SELECT id FROM organizations WHERE name = 'Cmazon' ORDER BY id DESC LIMIT 1) |
||||
|
) |
||||
|
,( |
||||
|
(SELECT id FROM organizations WHERE name = 'Bmazon' ORDER BY id DESC LIMIT 1), |
||||
|
(SELECT id FROM organizations WHERE name = 'Zcrosoft' ORDER BY id DESC LIMIT 1) |
||||
|
) |
||||
|
,( |
||||
|
(SELECT id FROM organizations WHERE name = 'Zcrosoft' ORDER BY id DESC LIMIT 1), |
||||
|
(SELECT id FROM organizations WHERE name = 'Ncrosoft' ORDER BY id DESC LIMIT 1) |
||||
|
) |
||||
|
; |
||||
|
|
||||
|
commit; |
@ -0,0 +1,34 @@ |
|||||
|
CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public; |
||||
|
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; |
||||
|
|
||||
|
CREATE TABLE addresses ( |
||||
|
"id" bigserial PRIMARY KEY NOT NULL, |
||||
|
"address_line_1" character varying(255) NOT NULL, |
||||
|
"address_line_2" character varying(255), |
||||
|
"city" character varying(255) NOT NULL, |
||||
|
"region" character varying(255) NOT NULL, |
||||
|
"country" character varying(255) NOT NULL, |
||||
|
"zip_code" character varying(255) NOT NULL, |
||||
|
"phone" character varying(255) NOT NULL, |
||||
|
"uuid" UUID UNIQUE NOT NULL DEFAULT uuid_generate_v4() |
||||
|
); |
||||
|
|
||||
|
CREATE TYPE organization_type AS ENUM ('CUSTOMER', 'ENTERPRISE', 'ENTERPRISE_CUSTOMER'); |
||||
|
|
||||
|
CREATE TABLE organizations ( |
||||
|
"id" bigserial PRIMARY KEY NOT NULL, |
||||
|
"name" character varying(100) NOT NULL, |
||||
|
"address_id" integer UNIQUE NOT NULL REFERENCES addresses("id"), |
||||
|
"type" organization_type NOT NULL, |
||||
|
"created_at" timestamp with time zone NOT NULL DEFAULT NOW(), |
||||
|
"uuid" UUID UNIQUE NOT NULL DEFAULT uuid_generate_v4() |
||||
|
); |
||||
|
|
||||
|
CREATE TABLE enterprise_sales_enterprise_customers ( |
||||
|
"sales_organization_id" bigint NOT NULL REFERENCES organizations("id"), |
||||
|
"customer_organization_id" bigint NOT NULL REFERENCES organizations("id"), |
||||
|
CONSTRAINT sales_organization_customer_organization_key PRIMARY KEY ( |
||||
|
sales_organization_id, |
||||
|
customer_organization_id |
||||
|
) |
||||
|
); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue