Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
Add official support for redshift (postgres 8.0) (#109)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Peveler <[email protected]>
  • Loading branch information
MasterOdin authored Aug 12, 2020
1 parent bd9cfc5 commit ff48183
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 95 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:
build:
runs-on: ubuntu-latest

env:
redshift-version: redshift

strategy:
matrix:
include:
Expand Down Expand Up @@ -49,12 +52,19 @@ jobs:

- name: Create MySQL Container
run: docker run --rm -d --name mysql -e "MYSQL_ROOT_PASSWORD=Password12!" -e "MYSQL_DATABASE=sqlectron" -p 3306:3306 -v ${GITHUB_WORKSPACE}/spec/databases/mysql/schema:/docker-entrypoint-initdb.d mysql:${{ matrix.mysql-version }}

- name: Create MariaDB Container
run: docker run --rm -d --name mariadb -e "MYSQL_ROOT_PASSWORD=Password12!" -e "MYSQL_DATABASE=sqlectron" -p 3307:3306 -v ${GITHUB_WORKSPACE}/spec/databases/mysql/schema:/docker-entrypoint-initdb.d mariadb:${{ matrix.maraidb-version }}

- name: Create Postgres Container
run: docker run --rm -d --name postgres -e "POSTGRES_PASSWORD=Password12!" -e "POSTGRES_DB=sqlectron" -p 5432:5432 -v ${GITHUB_WORKSPACE}/spec/databases/postgresql/schema:/docker-entrypoint-initdb.d postgres:${{ matrix.postgres-version }}

- name: Create Redshift Container
run: docker run --rm -d --name redshift -e "POSTGRES_PASSWORD=Password12!" -e "POSTGRES_DATABASE=sqlectron" -p 5433:5432 -v ${GITHUB_WORKSPACE}/spec/databases/redshift/schema:/docker-entrypoint-initdb.d foundryai/postgres8:${{ env.redshift-version }}

- name: Create Cassandra Container
run: docker run --rm -d --name cassandra -p 9042:9042 -v ${GITHUB_WORKSPACE}/spec/databases/cassandra/schema:/docker-entrypoint-initdb.d cassandra:${{ matrix.cassandra-version }}

- name: Create SQLServer Container
run: docker run --rm -d --name sqlserver -p 1433:1433 -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Password12!" -e "MSSQL_COLLATION=${{ matrix.sqlserver-collation }}" -v ${GITHUB_WORKSPACE}/spec/databases/sqlserver/schema:/docker-entrypoint-initdb.d mcr.microsoft.com/mssql/server:2017-latest

Expand Down Expand Up @@ -82,4 +92,4 @@ jobs:
- name: Initialize SQLServer Schema
run: docker exec -i sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U sa -P Password12! -i /docker-entrypoint-initdb.d/schema.sql -d "sqlectron"

- run: DB_CLIENTS=mysql,mariadb,postgresql,sqlite,sqlserver,cassandra npm run test:coverage
- run: DB_CLIENTS=mysql,mariadb,postgresql,redshift,sqlite,sqlserver,cassandra npm run test:coverage
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ services:
volumes:
- ./spec/databases/postgresql/schema:/docker-entrypoint-initdb.d

redshift:
image: foundryai/postgres8:redshift
ports:
- 5433:5432
environment:
POSTGRES_PASSWORD: password
POSTGRES_DATABASE: sqlectron
volumes:
- ./spec/databases/redshift/schema:/docker-entrypoint-initdb.d

cassandra:
image: cassandra:3.7
environment:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"test:sqlite": "DB_CLIENTS=sqlite npm run test",
"test:sqlserver": "DB_CLIENTS=sqlserver npm run test",
"test:postgresql": "DB_CLIENTS=postgresql npm run test",
"test:redshift": "DB_CLIENTS=redshift npm run test",
"test:cassandra": "DB_CLIENTS=cassandra npm run test",
"test": "npm run lint && mocha --exit --timeout 40000 --require @babel/register --reporter spec \"./spec/**/*.spec.js\"",
"test:coverage": "nyc --reporter=text mocha --exit --timeout 4000 --require @babel/register --reporter spec \"./spec/**/*.spec.js\"",
Expand Down
17 changes: 16 additions & 1 deletion spec/databases/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const postgres = new ConnectionString(process.env.POSTGRES_DSN, {
user: 'postgres',
password: 'Password12!',
path: ['sqlectron'],
hosts: [{ name: 'localhost', port: 5432 }],
hosts: [{ name: '127.0.0.1', port: 5432 }],
});
dbs.postgresql = {
host: postgres.hostname,
Expand All @@ -22,6 +22,21 @@ dbs.postgresql = {
database: postgres.path && postgres.path[0],
};

const redshift = new ConnectionString(process.env.REDSHIFT_DSN, {
protocol: 'postgres',
user: 'postgres',
password: 'Password12!',
path: ['sqlectron'],
hosts: [{ name: '127.0.0.1', port: 5433 }],
});
dbs.redshift = {
host: redshift.hostname,
port: redshift.port || 5433,
user: redshift.user,
password: redshift.password,
database: redshift.path && redshift.path[0],
};

const mysql = new ConnectionString(process.env.MYSQL_DSN, {
protocol: 'mysql',
user: 'root',
Expand Down
26 changes: 26 additions & 0 deletions spec/databases/redshift/schema/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
CREATE TABLE roles(
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);

CREATE TABLE users(
id SERIAL PRIMARY KEY,
username TEXT NOT NULL,
email TEXT NOT NULL,
password TEXT NOT NULL,
role_id INT REFERENCES roles (id) ON DELETE CASCADE,
createdat DATE NULL
);

CREATE OR REPLACE VIEW email_view AS
SELECT users.email, users.password
FROM users;

CREATE OR REPLACE FUNCTION users_count()
RETURNS bigint AS $$
SELECT COUNT(*) FROM users AS total;
$$ LANGUAGE SQL;

-- Redshift does not support triggers

CREATE SCHEMA dummy_schema;
Loading

0 comments on commit ff48183

Please sign in to comment.