Skip to content

Commit

Permalink
fix: use migration both in tests and in docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Dec 13, 2023
1 parent 620d09d commit 083c22c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 43 deletions.
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ services:
- MARIADB_ROOT_PASSWORD=root
ports:
- "3306:3306"
volumes:
- ./migrations/init.sql:/docker-entrypoint-initdb.d/init.sql
3 changes: 0 additions & 3 deletions knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ export default _.merge({}, ...[ 'development', 'production', 'staging', 'test' ]
seeds: {
directory: `./seeds/${environment}`,
},
migrations: {
directory: `./migrations/${environment}`,
},
},
};
}));
13 changes: 13 additions & 0 deletions migrations/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Bluebird from 'bluebird';
import fs from 'node:fs';
import path from 'path';
import { fileURLToPath } from 'url';

export const up = async (db) => {
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const sql = fs.readFileSync(path.join(__dirname, 'init.sql'), 'utf8');
const queries = sql.split('\n\n');
await Bluebird.map(queries, query => db.schema.raw(query));
};

export const down = () => {};
36 changes: 36 additions & 0 deletions migrations/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
CREATE TABLE IF NOT EXISTS adopted_probes (
id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
user_created CHAR(36),
date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
user_updated CHAR(36),
date_updated TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
userId VARCHAR(255) NOT NULL,
ip VARCHAR(255) NOT NULL,
uuid VARCHAR(255),
lastSyncDate DATE NOT NULL,
isCustomCity TINYINT DEFAULT 0,
tags LONGTEXT,
status VARCHAR(255) NOT NULL,
version VARCHAR(255) NOT NULL,
country VARCHAR(255) NOT NULL,
city VARCHAR(255),
state VARCHAR(255),
latitude FLOAT(10, 5),
longitude FLOAT(10, 5),
asn INTEGER NOT NULL,
network VARCHAR(255) NOT NULL,
countryOfCustomCity VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS directus_users (
id CHAR(36),
github VARCHAR(255)
);

CREATE TABLE IF NOT EXISTS directus_notifications (
id CHAR(10),
recipient CHAR(36),
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
subject VARCHAR(255),
message TEXT
);
40 changes: 0 additions & 40 deletions migrations/test/index.js

This file was deleted.

0 comments on commit 083c22c

Please sign in to comment.