Skip to content

Commit

Permalink
Upgrade deps (#109)
Browse files Browse the repository at this point in the history
* updated deps, did cleanup, fixed and added tests, updated ci
* updated postgres version
* bumped versions
* fixed fmt test in ci
* fmt
  • Loading branch information
halvardssm authored Apr 29, 2021
1 parent afe4655 commit 289daa0
Show file tree
Hide file tree
Showing 30 changed files with 193 additions and 99 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI

env:
DENO_VERSION: 1.8.3
DENO_VERSION: 1.9.2

on:
push:
Expand All @@ -12,6 +12,22 @@ on:
- main

jobs:
fmt:
name: Test format and lint
runs-on: ubuntu-latest

steps:
- name: Clone repo
uses: actions/checkout@master

- name: Install deno
uses: denoland/setup-deno@main
with:
deno-version: ${{env.DENO_VERSION}}

- name: Run test for format and lint
run: make test-fmt

cli:
name: Test CLI
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish_nest.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Publish Egg

env:
DENO_VERSION: 1.8.3
DENO_VERSION: 1.9.2
NEST_VERSION: 0.3.6

on:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ DB_USER=root
DB_PWD=pwd
DB_NAME=nessie

test-all: db-all-restart test-cli-migrations db-all-restart test-cli-migrations-experimental test-cli-update-timestamps
test-all: test-fmt db-all-restart test-cli-migrations db-all-restart test-cli-migrations-experimental test-cli-update-timestamps

test-fmt:
deno lint --unstable --ignore=tests,examples,cli/templates
deno fmt --check

test-cli-migrations:
deno test -A --unstable tests/cli
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/halvardssm/deno-nessie?label=Nessie%20stable&style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEUAAABL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lQv238747uaMubbQyPDuYQpbkLcOoi9dUM49P217WuzTpQsUi9MhHpcXXLpDr/bVNWATphjPjfZtzbMplD6jEltrPAeI76hrLqrBz1qEScl4xfqEZuSP4/aLLwWOQC9ScAAAAASUVORK5CYII=)](https://deno.land/x/nessie)
[![(Deno)](https://img.shields.io/badge/deno-v1.8.3-green.svg?style=flat-square&logo=deno)](https://deno.land)
[![(Deno)](https://img.shields.io/badge/deno-v1.9.2-green.svg?style=flat-square&logo=deno)](https://deno.land)
[![GitHub Workflow Status (branch)](https://img.shields.io/github/workflow/status/halvardssm/deno-nessie/ci/master?style=flat-square&logo=github)](https://github.com/halvardssm/deno-nessie/actions?query=branch%3Amaster+workflow%3ACI)
[![(query-builder)](https://img.shields.io/badge/query_builder-doc-informational.svg?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEUAAABLCAYAAAAmh0pZAAAACXBIWXMAAAEjAAABIwFyQXfeAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAABltJREFUeJztnF2MHlUZx3+nXWlBWsJXaAWElI+iIBIhaAPcaDUEUrghApEQEhIMmKA1jTcmGkOUQPhKFC4gEFNpUuQC0l4YlK8CsUBLjBI+2m4pRdsldWuLLN3WbvfnxZk3u7zMO+/M+87szG75Jc3unnPmnOf5z5mZc55zTqFH1MvUP6ib1VF1p/qceot6VK/1TkvUE9WnzGZQvaxuW6cE9cvq1i6CtNivXl23zZWiHq1uyilIi1H1wrptrwz1kYKCtNikHlG3/aWjfkU91KMoqj+u24fSUR/qQxDVYfWLdfuRl1k5yy3rs53jgWv6rGPK6CqKuhA4pYS2Zo4owBkltbVUnVdSXZWSR5Sy3gVzgW+UVFel5BFloMT2Ti6xrsrI+6Iti7lT3F5P5BHl4xLb21RiXZXRjyjrC7a1A9hY8JpayCPKnJS0YeB7wLMF2vp5COFAgfLNRV2aMkJ9Pck7Qn3A7CnAfvX2uv0oFfWGFEdXt5X5mvqoOpTk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7u94g9fQTYT775WYvtmQ6rTwDf79HI6cpQN1FOBf5GPO52uPBot007u4F/ECd1M5lPgHXEYNgtWe+UZcD9lHdcrimMA+8QJ62vEocab4UQxloFPiOKuhT4NXDxFBlZNbuIzrdE2BBCyNxjEyCexiCu/q1geotxCHgL+CtxHLM+hLClaCVBvRG4k4kljOnGGLAaeAp4IYSwp98KB4hR++m8KL6NibhM34IAoP7M3qb6Q8bj/v/qc6JXJuvU88sS5hL1SfXjHA1vNy6QzU+unaPeZFwibQKjaqdViFx86uujDhD3ui0GzmRi+XQfMZS4IYTwdoa45xD3sJzaj1Ft/IeJBbq8jAIXhBA2l2hH7xhjLHl6nMZe96DpYc8x9TtJnat66DGr6tbiU6hXJE51YzgpP0f9ICX/riR/vsUfz+F6VUhB/YH6vxzGn5KUP9sY3x2elPf7SfUdp75SQJQPa3M+C2OP2dPF+LParhlQv238747uaMubbQyPDuYQpbkLcOoi9dUM49P217WuzTpQsUi9MhHpcXXLpDr/bVNWATphjPjfZtzbMplD6jEltrPAeI76hrLqrBz1qEScl4xfqEZuSP4/aLLwWOQC9ScAAAAASUVORK5CYII=)](https://doc.deno.land/https/deno.land/x/nessie/qb.ts)
[![(clients)](https://img.shields.io/badge/clients-doc-informational.svg?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEUAAABLCAYAAAAmh0pZAAAACXBIWXMAAAEjAAABIwFyQXfeAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAABltJREFUeJztnF2MHlUZx3+nXWlBWsJXaAWElI+iIBIhaAPcaDUEUrghApEQEhIMmKA1jTcmGkOUQPhKFC4gEFNpUuQC0l4YlK8CsUBLjBI+2m4pRdsldWuLLN3WbvfnxZk3u7zMO+/M+87szG75Jc3unnPmnOf5z5mZc55zTqFH1MvUP6ib1VF1p/qceot6VK/1TkvUE9WnzGZQvaxuW6cE9cvq1i6CtNivXl23zZWiHq1uyilIi1H1wrptrwz1kYKCtN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nUiwHSrerq6t4tTf1cvT649SX3Mz64/F+UjdbV6nU2ZJhiPvn2kflM9T13XZvRe4xzou+os9UjjXe4mYC+MqPeoJ9UtytOT7tgKda6xF5xv8ogk5c5T7zP/o9IP+xJxKu857TsKWs4uJw7MWowArxFfjAALgSXEz/ZUsxNYHkL4Y1UNdBJlIfBPis2Ip5r1wJ0hhLVlV5wajgwhDAF/KbuxklkCrFFfNM7XSjtkldpTANRLgZeyyjSMA8AG4q7u94g9fQTYT775WYvtmQ6rTwDf79HI6cpQN1FOBf5GPO52uPBot007u4F/ECd1M5lPgHXEYNgtWe+UZcD9lHdcrimMA+8QJ62vEocab4UQxloFPiOKuhT4NXDxFBlZNbuIzrdE2BBCyNxjEyCexiCu/q1geotxCHgL+CtxHLM+hLClaCVBvRG4k4kljOnGGLAaeAp4IYSwp98KB4hR++m8KL6NibhM34IAoP7M3qb6Q8bj/v/qc6JXJuvU88sS5hL1SfXjHA1vNy6QzU+unaPeZFwibQKjaqdViFx86uujDhD3ui0GzmRi+XQfMZS4IYTwdoa45xD3sJzaj1Ft/IeJBbq8jAIXhBA2l2hH7xhjLHl6nMZe96DpYc8x9TtJnat66DGr6tbiU6hXJE51YzgpP0f9ICX/riR/vsUfz+F6VUhB/YH6vxzGn5KUP9sY3x2elPf7SfUdp75SQJQPa3M+C2OP2dPF+LParhlQv238747uaMubbQyPDuYQpbkLcOoi9dUM49P217WuzTpQsUi9MhHpcXXLpDr/bVNWATphjPjfZtzbMplD6jEltrPAeI76hrLqrBz1qEScl4xfqEZuSP4/aLLwWOQC9ScAAAAASUVORK5CYII=)](https://doc.deno.land/https/deno.land/x/nessie/mod.ts)
Expand Down Expand Up @@ -74,7 +74,8 @@ Nessie is available through:
`deno run --allow-net --allow-read https://deno.land/x/nessie/cli.ts seed ".+.ts"`

- `update_timestamps`: Update timestamps - will update timestamps to the new
format. Will only update timestams where the value is less than 1672531200000 (2023-01-01) so that the timestamps wont be updated multiple times.
format. Will only update timestams where the value is less than 1672531200000
(2023-01-01) so that the timestamps wont be updated multiple times.

`deno run --allow-read --allow-write https://deno.land/x/nessie/cli.ts update_timestamps`

Expand Down
12 changes: 6 additions & 6 deletions cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const initNessie = async () => {
await Deno.create(resolve(Deno.cwd(), "db/seeds/.gitkeep"));
};

const updateTimestamps = () => {
const updateTimestamps = async () => {
const migrationFiles = [...Deno.readDirSync(Deno.cwd())];

const filteredMigrations = migrationFiles
Expand All @@ -94,17 +94,17 @@ const updateTimestamps = () => {
};
});

filteredMigrations.forEach(({ oldName, newName }) => {
Deno.renameSync(oldName, newName);
});
for await (const { oldName, newName } of filteredMigrations) {
await Deno.rename(oldName, newName);
}

const output = filteredMigrations
.map(({ oldName, newName }) => `${oldName} => ${newName}`)
.join("\n");

const encoder = new TextEncoder();

Deno.stdout.writeSync(encoder.encode(output));
await Deno.stdout.write(encoder.encode(output));
};

/** Main application */
Expand All @@ -131,7 +131,7 @@ const run = async () => {
} else if (prog.seed) {
await state.client!.seed(prog.matcher);
} else if (prog.update_timestamps) {
updateTimestamps();
await updateTimestamps();
await state.client!.updateTimestamps();
}

Expand Down
1 change: 1 addition & 0 deletions cli/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class State {
}

/** A logger to use throughout the application, outputs when the debugger is enabled */
// deno-lint-ignore no-explicit-any
logger(output?: any, title?: string): void {
try {
if (this.enableDebug) {
Expand Down
6 changes: 3 additions & 3 deletions cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const parsePath = (...path: string[]): string => {
};

export const isUrl = (path: string) => {
return path.startsWith("http://")
|| path.startsWith("https://")
|| path.startsWith("file://")
return path.startsWith("http://") ||
path.startsWith("https://") ||
path.startsWith("file://");
};
1 change: 1 addition & 0 deletions clients/AbstractClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export abstract class AbstractClient<Client> {
} else {
for await (const file of files) {
if (this.experimental) {
// deno-lint-ignore no-explicit-any
const exposedObject: Info<any> = {
dialect: this.dialect!,
connection: queryHandler,
Expand Down
40 changes: 20 additions & 20 deletions clients/ClientMySQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ import {

/** MySQL client */
export class ClientMySQL extends AbstractClient<Client> implements ClientI {
private clientOptions: ClientConfig;
#clientOptions: ClientConfig;
dialect: DBDialects = "mysql";

private QUERY_TRANSACTION_START = `START TRANSACTION;`;
private QUERY_TRANSACTION_COMMIT = `COMMIT;`;
private QUERY_TRANSACTION_ROLLBACK = `ROLLBACK;`;
#QUERY_TRANSACTION_START = `START TRANSACTION;`;
#QUERY_TRANSACTION_COMMIT = `COMMIT;`;
#QUERY_TRANSACTION_ROLLBACK = `ROLLBACK;`;

private QUERY_MIGRATION_TABLE_EXISTS =
#QUERY_MIGRATION_TABLE_EXISTS =
`SELECT * FROM information_schema.tables WHERE table_name = '${TABLE_MIGRATIONS}' LIMIT 1;`;

private QUERY_CREATE_MIGRATION_TABLE =
#QUERY_CREATE_MIGRATION_TABLE =
`CREATE TABLE ${TABLE_MIGRATIONS} (id bigint UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, ${COL_FILE_NAME} varchar(${MAX_FILE_NAME_LENGTH}) NOT NULL UNIQUE, ${COL_CREATED_AT} datetime NOT NULL DEFAULT CURRENT_TIMESTAMP);`;

private QUERY_UPDATE_TIMESTAMPS =
#QUERY_UPDATE_TIMESTAMPS =
`UPDATE ${TABLE_MIGRATIONS} SET ${COL_FILE_NAME} = CONCAT(FROM_UNIXTIME(CAST(substring_index(${COL_FILE_NAME}, '-', 1) AS SIGNED) / 1000, '%Y%m%d%H%i%S'), substring(file_name, instr( file_name,'-'))) WHERE CAST(substring_index(${COL_FILE_NAME}, '-', 1) AS SIGNED) < 1672531200000;`;

constructor(
Expand All @@ -41,35 +41,35 @@ export class ClientMySQL extends AbstractClient<Client> implements ClientI {
...options,
client: new Client(),
});
this.clientOptions = connectionOptions;
this.#clientOptions = connectionOptions;
}

async prepare() {
await this.client.connect(this.clientOptions);
const queryResult = await this.query(this.QUERY_MIGRATION_TABLE_EXISTS);
await this.client.connect(this.#clientOptions);
const queryResult = await this.query(this.#QUERY_MIGRATION_TABLE_EXISTS);

const migrationTableExists = queryResult?.[0]?.length > 0;

if (!migrationTableExists) {
await this.query(this.QUERY_CREATE_MIGRATION_TABLE);
await this.query(this.#QUERY_CREATE_MIGRATION_TABLE);
console.info("Database setup complete");
}
}

async updateTimestamps() {
await this.client.connect(this.clientOptions);
const queryResult = await this.query(this.QUERY_MIGRATION_TABLE_EXISTS);
await this.client.connect(this.#clientOptions);
const queryResult = await this.query(this.#QUERY_MIGRATION_TABLE_EXISTS);

const migrationTableExists = queryResult?.[0]?.length > 0;

if (migrationTableExists) {
await this.query(this.QUERY_TRANSACTION_START);
await this.query(this.#QUERY_TRANSACTION_START);
try {
await this.query(this.QUERY_UPDATE_TIMESTAMPS);
await this.query(this.QUERY_TRANSACTION_COMMIT);
await this.query(this.#QUERY_UPDATE_TIMESTAMPS);
await this.query(this.#QUERY_TRANSACTION_COMMIT);
console.info("Updated timestamps");
} catch (e) {
await this.query(this.QUERY_TRANSACTION_ROLLBACK);
await this.query(this.#QUERY_TRANSACTION_ROLLBACK);
throw e;
}
}
Expand Down Expand Up @@ -117,9 +117,9 @@ export class ClientMySQL extends AbstractClient<Client> implements ClientI {
async rollback(amount: AmountRollbackT) {
const allMigrations = await this.query(this.QUERY_GET_ALL);

const parsedMigrations: string[] = allMigrations?.[0].map((el: any) =>
el?.[COL_FILE_NAME]
);
const parsedMigrations: string[] = allMigrations?.[0].map((
el: Record<string, string>,
) => el?.[COL_FILE_NAME]);

await super.rollback(
amount,
Expand Down
Loading

0 comments on commit 289daa0

Please sign in to comment.