diff --git a/docker-compose.yml b/docker-compose.yml index 95e4bfe..590f955 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -26,13 +26,13 @@ services: environment: - ACCEPT_EULA=Y - SA_PASSWORD=Test@123 - working_dir: /usr/src/app - command: sh -c ' chmod +x ./scripts/mssql-entrypoint.sh; ./scripts/mssql-entrypoint.sh & /opt/mssql/bin/sqlservr;' + working_dir: /tmp/test + command: sh -c './scripts/mssql-entrypoint.sh & /opt/mssql/bin/sqlservr' ports: - 1433:1433 volumes: - mssql-volume:/var/opt/mssql/ - - ./test:/usr/src/app + - ./test:/tmp/test # Note: you need to be logged in to DockerHub, and accept the EULA for oracle/database-enterprise to work # ... no clue how to get around that in GH Actions for tests ... @@ -44,14 +44,19 @@ services: # - 1521:32769 # - 5500:32768 # tty: true - # This is wat `knex` sues, but seems to crash with "ORA-01012: not logged on" - # oracledbxe: - # image: quillbuilduser/oracle-18-xe - # container_name: oracledbxe_container - # ports: - # - '21521:1521' - # environment: - # - ORACLE_ALLOW_REMOTE=true + + oracle: + image: quillbuilduser/oracle-18-xe-micro-sq + ports: + - 5104:1521 + environment: + - OPATCH_JRE_MEMORY_OPTIONS=-Xms128m -Xmx256m -XX:PermSize=16m -XX:MaxPermSize=32m -Xss1m + - ORACLE_ALLOW_REMOTE=true + shm_size: '1gb' + working_dir: /tmp/test + command: sh -c './scripts/oracle-entrypoint.sh' + volumes: + - ./test:/tmp/test volumes: mssql-volume: diff --git a/package.json b/package.json index a97b199..87a46ca 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "tsc --build", "prepare": "npm run build", "lint": "prettier --check .", - "test": "npm run lint && ts-mocha test/**/*.spec.ts" + "test": "npm run lint && ts-mocha test/**/*.spec.ts --timeout 10000" }, "repository": { "type": "git", diff --git a/test/oracle.spec.ts b/test/oracle.spec.ts index 338fec3..0ee2c53 100644 --- a/test/oracle.spec.ts +++ b/test/oracle.spec.ts @@ -3,7 +3,7 @@ import { expect } from 'chai'; import schemaInspector from '../lib'; import { SchemaInspector } from '../lib/types/schema-inspector'; -describe.skip('oracledb', () => { +describe('oracledb', () => { let database: Knex; let inspector: SchemaInspector; @@ -12,10 +12,10 @@ describe.skip('oracledb', () => { client: 'oracledb', connection: { host: '127.0.0.1', - port: 1521, - user: 'oracledb', - password: 'secret', - database: 'test_db', + port: 5104, + user: 'quill_test', + password: 'QuillRocks!', + database: 'xe', charset: 'utf8', }, }); @@ -62,9 +62,6 @@ describe.skip('oracledb', () => { describe('.columns', () => { it('returns information for all tables', async () => { expect(await inspector.columns()).to.deep.equal([ - { table: 'PAGE_VISITS', column: 'REQUEST_PATH' }, - { table: 'PAGE_VISITS', column: 'USER_AGENT' }, - { table: 'PAGE_VISITS', column: 'CREATED_AT' }, { table: 'TEAMS', column: 'ID' }, { table: 'TEAMS', column: 'UUID' }, { table: 'TEAMS', column: 'NAME' }, @@ -76,6 +73,9 @@ describe.skip('oracledb', () => { { table: 'USERS', column: 'TEAM_ID' }, { table: 'USERS', column: 'EMAIL' }, { table: 'USERS', column: 'PASSWORD' }, + { table: 'PAGE_VISITS', column: 'REQUEST_PATH' }, + { table: 'PAGE_VISITS', column: 'USER_AGENT' }, + { table: 'PAGE_VISITS', column: 'CREATED_AT' }, ]); }); @@ -94,28 +94,24 @@ describe.skip('oracledb', () => { describe('.columnInfo', () => { it('returns information for all columns in all tables', async () => { - expect(await inspector.columnInfo()).to.deep.equal([ - { - name: 'REQUEST_PATH', - table: 'PAGE_VISITS', - data_type: 'VARCHAR2', - default_value: null, - max_length: 100, - numeric_precision: null, - numeric_scale: null, - is_nullable: true, - is_unique: false, - is_primary_key: false, - foreign_key_column: null, - foreign_key_table: null, - comment: null, - }, + const columnInfo = await inspector.columnInfo(); + const teamInfo = columnInfo + .filter((column) => column.table == 'TEAMS') + .sort((a, b) => a.name.localeCompare(b.name)); + const usersInfo = columnInfo + .filter((column) => column.table == 'USERS') + .sort((a, b) => a.name.localeCompare(b.name)); + const pageVisitsInfo = columnInfo + .filter((column) => column.table == 'PAGE_VISITS') + .sort((a, b) => a.name.localeCompare(b.name)); + + expect([...teamInfo, ...usersInfo, ...pageVisitsInfo]).to.deep.equal([ { - name: 'USER_AGENT', - table: 'PAGE_VISITS', - data_type: 'VARCHAR2', + name: 'ACTIVATED_AT', + table: 'TEAMS', + data_type: 'DATE', default_value: null, - max_length: 200, + max_length: 7, numeric_precision: null, numeric_scale: null, is_nullable: true, @@ -127,7 +123,7 @@ describe.skip('oracledb', () => { }, { name: 'CREATED_AT', - table: 'PAGE_VISITS', + table: 'TEAMS', data_type: 'TIMESTAMP(0)', default_value: null, max_length: 7, @@ -141,49 +137,19 @@ describe.skip('oracledb', () => { comment: null, }, { - name: 'ID', + name: 'CREDITS', table: 'TEAMS', data_type: 'NUMBER', default_value: null, max_length: 22, numeric_precision: 10, numeric_scale: 0, - is_nullable: false, - is_unique: false, - is_primary_key: true, - foreign_key_column: null, - foreign_key_table: null, - comment: null, - }, - { - name: 'UUID', - table: 'TEAMS', - data_type: 'CHAR', - default_value: null, - max_length: 36, - numeric_precision: null, - numeric_scale: null, - is_nullable: false, - is_unique: true, - is_primary_key: false, - foreign_key_column: null, - foreign_key_table: null, - comment: null, - }, - { - name: 'NAME', - table: 'TEAMS', - data_type: 'VARCHAR2', - default_value: null, - max_length: 100, - numeric_precision: null, - numeric_scale: null, is_nullable: true, is_unique: false, is_primary_key: false, foreign_key_column: null, foreign_key_table: null, - comment: null, + comment: 'Remaining usage credits', }, { name: 'DESCRIPTION', @@ -201,28 +167,28 @@ describe.skip('oracledb', () => { comment: null, }, { - name: 'CREDITS', + name: 'ID', table: 'TEAMS', data_type: 'NUMBER', default_value: null, max_length: 22, numeric_precision: 10, numeric_scale: 0, - is_nullable: true, + is_nullable: false, is_unique: false, - is_primary_key: false, + is_primary_key: true, foreign_key_column: null, foreign_key_table: null, - comment: 'Remaining usage credits', + comment: null, }, { - name: 'CREATED_AT', + name: 'NAME', table: 'TEAMS', - data_type: 'TIMESTAMP(0)', + data_type: 'VARCHAR2', default_value: null, - max_length: 7, + max_length: 100, numeric_precision: null, - numeric_scale: 0, + numeric_scale: null, is_nullable: true, is_unique: false, is_primary_key: false, @@ -231,11 +197,26 @@ describe.skip('oracledb', () => { comment: null, }, { - name: 'ACTIVATED_AT', + name: 'UUID', table: 'TEAMS', - data_type: 'DATE', + data_type: 'CHAR', default_value: null, - max_length: 7, + max_length: 36, + numeric_precision: null, + numeric_scale: null, + is_nullable: false, + is_unique: true, + is_primary_key: false, + foreign_key_column: null, + foreign_key_table: null, + comment: null, + }, + { + name: 'EMAIL', + table: 'USERS', + data_type: 'VARCHAR2', + default_value: null, + max_length: 100, numeric_precision: null, numeric_scale: null, is_nullable: true, @@ -260,6 +241,21 @@ describe.skip('oracledb', () => { foreign_key_table: null, comment: null, }, + { + name: 'PASSWORD', + table: 'USERS', + data_type: 'VARCHAR2', + default_value: null, + max_length: 60, + numeric_precision: null, + numeric_scale: null, + is_nullable: true, + is_unique: false, + is_primary_key: false, + foreign_key_column: null, + foreign_key_table: null, + comment: null, + }, { name: 'TEAM_ID', table: 'USERS', @@ -276,8 +272,23 @@ describe.skip('oracledb', () => { comment: null, }, { - name: 'EMAIL', - table: 'USERS', + name: 'CREATED_AT', + table: 'PAGE_VISITS', + data_type: 'TIMESTAMP(0)', + default_value: null, + max_length: 7, + numeric_precision: null, + numeric_scale: 0, + is_nullable: true, + is_unique: false, + is_primary_key: false, + foreign_key_column: null, + foreign_key_table: null, + comment: null, + }, + { + name: 'REQUEST_PATH', + table: 'PAGE_VISITS', data_type: 'VARCHAR2', default_value: null, max_length: 100, @@ -291,11 +302,11 @@ describe.skip('oracledb', () => { comment: null, }, { - name: 'PASSWORD', - table: 'USERS', + name: 'USER_AGENT', + table: 'PAGE_VISITS', data_type: 'VARCHAR2', default_value: null, - max_length: 60, + max_length: 200, numeric_precision: null, numeric_scale: null, is_nullable: true, @@ -309,60 +320,64 @@ describe.skip('oracledb', () => { }); it('returns information for all columns in specific table', async () => { - expect(await inspector.columnInfo('TEAMS')).to.deep.equal([ + const columnInfo = await inspector.columnInfo('TEAMS'); + + expect( + columnInfo.sort((a, b) => a.name.localeCompare(b.name)) + ).to.deep.equal([ { - name: 'CREDITS', + name: 'ACTIVATED_AT', table: 'TEAMS', - data_type: 'NUMBER', + data_type: 'DATE', default_value: null, - max_length: 22, - numeric_precision: 10, - numeric_scale: 0, + max_length: 7, + numeric_precision: null, + numeric_scale: null, is_nullable: true, is_unique: false, is_primary_key: false, foreign_key_column: null, foreign_key_table: null, - comment: 'Remaining usage credits', + comment: null, }, { - name: 'ID', + name: 'CREATED_AT', table: 'TEAMS', - data_type: 'NUMBER', + data_type: 'TIMESTAMP(0)', default_value: null, - max_length: 22, - numeric_precision: 10, + max_length: 7, + numeric_precision: null, numeric_scale: 0, - is_nullable: false, + is_nullable: true, is_unique: false, - is_primary_key: true, + is_primary_key: false, foreign_key_column: null, foreign_key_table: null, comment: null, }, { - name: 'NAME', + name: 'CREDITS', table: 'TEAMS', - data_type: 'VARCHAR2', + data_type: 'NUMBER', default_value: null, - max_length: 100, - numeric_precision: null, - numeric_scale: null, + max_length: 22, + numeric_precision: 10, + numeric_scale: 0, is_nullable: true, is_unique: false, is_primary_key: false, foreign_key_column: null, foreign_key_table: null, - comment: null, + comment: 'Remaining usage credits', }, { - name: 'CREATED_AT', + name: 'DESCRIPTION', table: 'TEAMS', - data_type: 'TIMESTAMP(0)', + data_type: 'CLOB', default_value: null, - max_length: 7, + max_length: 4000, numeric_precision: null, - numeric_scale: 0, + numeric_scale: null, is_nullable: true, is_unique: false, is_primary_key: false, @@ -371,26 +386,26 @@ describe.skip('oracledb', () => { comment: null, }, { - name: 'UUID', + name: 'ID', table: 'TEAMS', - data_type: 'CHAR', + data_type: 'NUMBER', default_value: null, - max_length: 36, - numeric_precision: null, - numeric_scale: null, + max_length: 22, + numeric_precision: 10, + numeric_scale: 0, is_nullable: false, - is_unique: true, - is_primary_key: false, + is_unique: false, + is_primary_key: true, foreign_key_column: null, foreign_key_table: null, comment: null, }, { - name: 'DESCRIPTION', + name: 'NAME', table: 'TEAMS', - data_type: 'CLOB', + data_type: 'VARCHAR2', default_value: null, - max_length: 4000, + max_length: 100, numeric_precision: null, numeric_scale: null, is_nullable: true, @@ -401,15 +416,15 @@ describe.skip('oracledb', () => { comment: null, }, { - name: 'ACTIVATED_AT', + name: 'UUID', table: 'TEAMS', - data_type: 'DATE', + data_type: 'CHAR', default_value: null, - max_length: 7, + max_length: 36, numeric_precision: null, numeric_scale: null, - is_nullable: true, - is_unique: false, + is_nullable: false, + is_unique: true, is_primary_key: false, foreign_key_column: null, foreign_key_table: null, diff --git a/test/scripts/mssql-entrypoint.sh b/test/scripts/mssql-entrypoint.sh index e981821..c2c8bf9 100755 --- a/test/scripts/mssql-entrypoint.sh +++ b/test/scripts/mssql-entrypoint.sh @@ -1,17 +1,13 @@ #!/bin/bash + wait_time=15s password=Test@123 # wait for SQL Server to come up echo importing data will start in $wait_time... sleep $wait_time -echo importing data... # run the init script to create the DB and the tables in /table -/opt/mssql-tools/bin/sqlcmd -S 0.0.0.0 -U SA -P $password -i ./seed/init-mssql.sql +echo importing data... -for entry in "./seed/mssql.sql" -do - echo executing $entry - /opt/mssql-tools/bin/sqlcmd -S 0.0.0.0 -U SA -P $password -i $entry -done +/opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -U SA -P $password -i ./seed/mssql.sql diff --git a/test/scripts/oracle-entrypoint.sh b/test/scripts/oracle-entrypoint.sh new file mode 100755 index 0000000..2d74640 --- /dev/null +++ b/test/scripts/oracle-entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +username=quill_test +password=QuillRocks\! + +# bring up the server +$ORACLE_HOME/bin/lsnrctl start + +echo startup | $ORACLE_HOME/bin/sqlplus / as sysdba + +# run the init script to create the DB and the tables in /table +echo importing data... + +$ORACLE_HOME/bin/sqlplus -S $username/$password@127.0.0.1:1521/xe @/tmp/test/seed/oracle.sql + +tail -f $ORACLE_BASE/diag/rdbms/*/*/trace/alert*.log diff --git a/test/seed/init-mssql.sql b/test/seed/init-mssql.sql deleted file mode 100644 index 8166d5c..0000000 --- a/test/seed/init-mssql.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP DATABASE test_db -CREATE DATABASE test_db; -GO diff --git a/test/seed/mssql.sql b/test/seed/mssql.sql index 17d53a8..a78156e 100644 --- a/test/seed/mssql.sql +++ b/test/seed/mssql.sql @@ -1,4 +1,8 @@ -USE test_db; +drop database test_db; +create database test_db; +GO + +use test_db; GO create table teams ( @@ -32,4 +36,4 @@ create table page_visits ( created_at datetime2(0) ); -GO \ No newline at end of file +GO diff --git a/test/seed/oracle.sql b/test/seed/oracle.sql index 3e85842..d4bef6a 100644 --- a/test/seed/oracle.sql +++ b/test/seed/oracle.sql @@ -1,6 +1,3 @@ -create user db_test identified by db_test; -alter session set current_schema = db_test; - create table teams ( id number(10) not null primary key, uuid char(36) not null,