Skip to content

Commit

Permalink
ci: update docker setup and failing mysql tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Mar 1, 2022
1 parent 851b23f commit a118455
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ PG_PORT=5432
PG_USER=virk
PG_PASSWORD=password

MSSQL_SERVER=mssql
MSSQL_SERVER=microsoftsql
MSSQL_USER=sa
MSSQL_PASSWORD=arandom&233password
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@ WORKDIR /usr/src/app
COPY package*.json ./
RUN HUSKY_SKIP_INSTALL=1 npm install --build-from-source --python=/usr/bin/python3

RUN wget https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh -O /wait-for-it.sh
RUN chmod +x /wait-for-it.sh

COPY . .

COPY ./start.sh /start.sh
RUN chmod +x /start.sh

RUN npm run build
4 changes: 2 additions & 2 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ services:
- mysql_replica_2
- mysql
- pg
- mssql
command: ['npm', 'run', 'test:docker']
- microsoftsql
command: ['/start.sh']
22 changes: 17 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ services:
MYSQL_ROOT_PASSWORD: password
ports:
- '3306:3306'
expose:
- '3306'
mysql_replica_1:
platform: linux/x86_64
image: mysql:5.7
Expand All @@ -20,6 +22,8 @@ services:
MYSQL_ROOT_PASSWORD: password
ports:
- '3304:3306'
expose:
- '3306'
mysql_replica_2:
platform: linux/x86_64
image: mysql:5.7
Expand All @@ -30,6 +34,8 @@ services:
MYSQL_ROOT_PASSWORD: password
ports:
- '3303:3306'
expose:
- '3306'
mysql:
platform: linux/x86_64
image: mysql:8.0
Expand All @@ -40,7 +46,9 @@ services:
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
ports:
- '3307:3306'
- '3305:3306'
expose:
- '3306'
pg:
image: postgres:11
environment:
Expand All @@ -49,10 +57,14 @@ services:
POSTGRES_PASSWORD: password
ports:
- 5432:5432
mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
expose:
- '5432'
microsoftsql:
image: mcr.microsoft.com/mssql/server:2019-latest
ports:
- 1433:1433
- 21433:1433
expose:
- '1433'
environment:
SA_PASSWORD: 'arandom&233password'
ACCEPT_EULA: 'true'
ACCEPT_EULA: 'Y'
7 changes: 0 additions & 7 deletions src/Database/QueryBuilder/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,6 @@ export class DatabaseQueryBuilder extends Chainable implements DatabaseQueryBuil
* Define returning columns
*/
public returning(columns: any): this {
/**
* Do not chain `returning` in sqlite3 to avoid knex warnings
*/
if (this.client && ['mysql'].includes(this.client.dialect.name)) {
return this
}

columns = Array.isArray(columns)
? columns.map((column) => this.resolveKey(column))
: this.resolveKey(columns)
Expand Down
7 changes: 0 additions & 7 deletions src/Database/QueryBuilder/Insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,6 @@ export class InsertQueryBuilder extends Macroable implements InsertQueryBuilderC
* Define returning columns for the insert query
*/
public returning(column: any): any {
/**
* Do not chain `returning` in sqlite3 to avoid knex warnings
*/
if (this.client && ['mysql'].includes(this.client.dialect.name)) {
return this
}

this.knexQuery.returning(column)
return this
}
Expand Down
8 changes: 7 additions & 1 deletion src/Orm/Adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import { Exception } from '@poppinss/utils'
import { DatabaseContract } from '@ioc:Adonis/Lucid/Database'
import { LucidRow, LucidModel, AdapterContract, ModelAdapterOptions } from '@ioc:Adonis/Lucid/Orm'
import { isObject } from '../../utils'

/**
* Adapter exposes the API to make database queries and constructor
Expand Down Expand Up @@ -65,7 +66,12 @@ export class Adapter implements AdapterContract {
const result = await query.insert(attributes).reporterData({ model: Model.name })

if (!Model.selfAssignPrimaryKey && Array.isArray(result) && result[0]) {
instance.$consumeAdapterResult(result[0])
if (isObject(result[0])) {
instance.$consumeAdapterResult(result[0])
} else {
const primaryKeyColumnName = this.getPrimaryKeyColumnName(Model)
instance.$consumeAdapterResult({ [primaryKeyColumnName]: result[0] })
}
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/Orm/QueryBuilder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,6 @@ export class ModelQueryBuilder extends Chainable implements ModelQueryBuilderCon
* Define returning columns
*/
public returning(columns: any): this {
/**
* Do not chain `returning` in sqlite3 to avoid knex warnings
*/
if (this.client && ['mysql'].includes(this.client.dialect.name)) {
return this
}

columns = Array.isArray(columns)
? columns.map((column) => this.resolveKey(column))
: this.resolveKey(columns)
Expand Down
3 changes: 3 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

/wait-for-it.sh mysql_legacy:3306 && /wait-for-it.sh mysql_replica_1:3306 && /wait-for-it.sh mysql_replica_2:3306 && /wait-for-it.sh mysql:3306 && /wait-for-it.sh pg:5432 && /wait-for-it.sh microsoftsql:1433 && npm run test:docker
Loading

0 comments on commit a118455

Please sign in to comment.