pgroll 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export const getMigrationFiles = (dir, direction) => {
4
+ const files = fs
5
+ .readdirSync(dir)
6
+ .filter(file => file.endsWith(`_${direction}.sql`));
7
+ if (direction == 'up') {
8
+ return files.sort();
9
+ }
10
+ return files.sort((a, b) => b.localeCompare(a));
11
+ };
12
+ export const createFolderIfNotExists = (filePath) => {
13
+ if (!fs.existsSync(filePath)) {
14
+ fs.mkdirSync(filePath, { recursive: true });
15
+ }
16
+ };
17
+ export const createFile = (migrationDir, name) => {
18
+ createFolderIfNotExists(migrationDir);
19
+ const timestamp = new Date().toISOString().replaceAll(/[.:TZ-]/g, '');
20
+ const ressult = [];
21
+ let fileName = `${timestamp}_${name}_up.sql`;
22
+ let filePath = path.join(migrationDir, fileName);
23
+ fs.writeFileSync(filePath, '-- up SQL here');
24
+ ressult.push(filePath);
25
+ fileName = `${timestamp}_${name}_down.sql`;
26
+ filePath = path.join(migrationDir, fileName);
27
+ fs.writeFileSync(filePath, '-- down SQL here');
28
+ ressult.push(filePath);
29
+ return ressult;
30
+ };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "pgroll",
3
+ "version": "0.0.2",
4
+ "description": "postgres migration",
5
+ "main": "dist/cjs/src/index.js",
6
+ "module": "dist/esm/src/index.js",
7
+ "types": "dist/cjs/src/index.d.ts",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/tnht95/pgroll"
11
+ },
12
+ "files": [
13
+ "dist/cjs/src",
14
+ "dist/esm/src"
15
+ ],
16
+ "bin": {
17
+ "pgroll": "./dist/cjs/src/cli.js"
18
+ },
19
+ "keywords": [
20
+ "postgres",
21
+ "sql",
22
+ "postgresjs",
23
+ "migration",
24
+ "javascript",
25
+ "typescript"
26
+ ],
27
+ "scripts": {
28
+ "dev": "tsx ./src/cli.ts",
29
+ "build-cjs": "tsc -p tsconfig.cjs.json",
30
+ "build-esm": "tsc -p tsconfig.esm.json",
31
+ "build": "rm -rf dist && pnpm build-cjs && pnpm build-esm",
32
+ "start": "node ./dist/index.js",
33
+ "fmt": "prettier --write .",
34
+ "fmtc": "prettier --check .",
35
+ "lint": "eslint . --fix",
36
+ "lintc": "eslint .",
37
+ "test": "jest"
38
+ },
39
+ "packageManager": "pnpm@9.4.0",
40
+ "engines": {
41
+ "node": ">=20.14.0",
42
+ "npm": "please-use-pnpm",
43
+ "yarn": "please-use-pnpm",
44
+ "pnpm": ">=9.4.0"
45
+ },
46
+ "license": "ISC",
47
+ "devDependencies": {
48
+ "@types/jest": "^29.5.12",
49
+ "@types/node": "^20.14.5",
50
+ "@typescript-eslint/eslint-plugin": "^7.13.1",
51
+ "eslint": "^8.5.0",
52
+ "eslint-config-prettier": "^9.1.0",
53
+ "eslint-import-resolver-typescript": "^3.6.1",
54
+ "eslint-plugin-import": "^2.29.1",
55
+ "eslint-plugin-jest": "^28.6.0",
56
+ "eslint-plugin-promise": "^6.2.0",
57
+ "eslint-plugin-sonarjs": "^1.0.3",
58
+ "eslint-plugin-unicorn": "^54.0.0",
59
+ "jest": "^29.7.0",
60
+ "prettier": "^3.3.2",
61
+ "ts-jest": "^29.1.5",
62
+ "tslib": "^2.6.3",
63
+ "tsx": "^4.15.6",
64
+ "typescript": "^5.4.5"
65
+ },
66
+ "dependencies": {
67
+ "commander": "^12.1.0",
68
+ "postgres": "^3.4.4"
69
+ }
70
+ }