@bejibun/database 0.1.11 → 0.1.12
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.
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file.
|
|
|
3
3
|
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
+
## [v0.1.12](https://github.com/crenata/bejibun-database/compare/v0.1.11...v0.1.12) - 2025-10-25
|
|
7
|
+
|
|
8
|
+
### 🩹 Fixes
|
|
9
|
+
- Fix `make:migration` counter undefined
|
|
10
|
+
|
|
11
|
+
### 📖 Changes
|
|
12
|
+
What's New :
|
|
13
|
+
- Adding `make:seeder` Create a new seeder file
|
|
14
|
+
|
|
15
|
+
### ❤️Contributors
|
|
16
|
+
- Havea Crenata ([@crenata](https://github.com/crenata))
|
|
17
|
+
- Ghulje ([@ghulje](https://github.com/ghulje))
|
|
18
|
+
|
|
19
|
+
**Full Changelog**: https://github.com/crenata/bejibun-database/blob/master/CHANGELOG.md
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
6
23
|
## [v0.1.11](https://github.com/crenata/bejibun-database/compare/v0.1.1...v0.1.11) - 2025-10-25
|
|
7
24
|
|
|
8
25
|
### 🩹 Fixes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import App from "@bejibun/app";
|
|
2
2
|
import Logger from "@bejibun/logger";
|
|
3
|
-
import { isEmpty } from "@bejibun/utils";
|
|
3
|
+
import { defineValue, isEmpty } from "@bejibun/utils";
|
|
4
4
|
import Luxon from "@bejibun/utils/facades/Luxon";
|
|
5
5
|
import path from "path";
|
|
6
6
|
export default class MakeMigrationCommand {
|
|
@@ -59,7 +59,7 @@ export default class MakeMigrationCommand {
|
|
|
59
59
|
}).filter((value) => {
|
|
60
60
|
return value.date === now;
|
|
61
61
|
}).map((value) => value.count).sort().reverse()[0];
|
|
62
|
-
const counter = parseInt(latest);
|
|
62
|
+
const counter = defineValue(parseInt(latest), 0);
|
|
63
63
|
const destination = `${migrationsDirectory}/${now}_${String(counter + 1).padStart(6, "0")}_${file}.ts`;
|
|
64
64
|
await Bun.write(App.Path.databasePath(destination), await Bun.file(path.resolve(migrationsPath, template)).text());
|
|
65
65
|
Logger.setContext("APP").info(`Migration [database/${destination}] created successfully.`);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default class MakeSeederCommand {
|
|
2
|
+
/**
|
|
3
|
+
* The name and signature of the console command.
|
|
4
|
+
*
|
|
5
|
+
* @var $signature string
|
|
6
|
+
*/
|
|
7
|
+
protected $signature: string;
|
|
8
|
+
/**
|
|
9
|
+
* The console command description.
|
|
10
|
+
*
|
|
11
|
+
* @var $description string
|
|
12
|
+
*/
|
|
13
|
+
protected $description: string;
|
|
14
|
+
/**
|
|
15
|
+
* The options or optional flag of the console command.
|
|
16
|
+
*
|
|
17
|
+
* @var $options Array<Array<any>>
|
|
18
|
+
*/
|
|
19
|
+
protected $options: Array<Array<any>>;
|
|
20
|
+
/**
|
|
21
|
+
* The arguments of the console command.
|
|
22
|
+
*
|
|
23
|
+
* @var $arguments Array<Array<string>>
|
|
24
|
+
*/
|
|
25
|
+
protected $arguments: Array<Array<string>>;
|
|
26
|
+
handle(options: any, args: Array<string>): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import App from "@bejibun/app";
|
|
2
|
+
import Logger from "@bejibun/logger";
|
|
3
|
+
import { defineValue, isEmpty } from "@bejibun/utils";
|
|
4
|
+
import Luxon from "@bejibun/utils/facades/Luxon";
|
|
5
|
+
import path from "path";
|
|
6
|
+
export default class MakeSeederCommand {
|
|
7
|
+
/**
|
|
8
|
+
* The name and signature of the console command.
|
|
9
|
+
*
|
|
10
|
+
* @var $signature string
|
|
11
|
+
*/
|
|
12
|
+
$signature = "make:seeder";
|
|
13
|
+
/**
|
|
14
|
+
* The console command description.
|
|
15
|
+
*
|
|
16
|
+
* @var $description string
|
|
17
|
+
*/
|
|
18
|
+
$description = "Create a new seeder file";
|
|
19
|
+
/**
|
|
20
|
+
* The options or optional flag of the console command.
|
|
21
|
+
*
|
|
22
|
+
* @var $options Array<Array<any>>
|
|
23
|
+
*/
|
|
24
|
+
$options = [];
|
|
25
|
+
/**
|
|
26
|
+
* The arguments of the console command.
|
|
27
|
+
*
|
|
28
|
+
* @var $arguments Array<Array<string>>
|
|
29
|
+
*/
|
|
30
|
+
$arguments = [
|
|
31
|
+
["<file>", "The name of the seeder file"]
|
|
32
|
+
];
|
|
33
|
+
async handle(options, args) {
|
|
34
|
+
if (isEmpty(args)) {
|
|
35
|
+
Logger.setContext("APP").error("There is no filename provided.");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const file = args[0];
|
|
39
|
+
const seedersDirectory = "seeders";
|
|
40
|
+
const seedersPath = path.resolve(__dirname, `../../database/${seedersDirectory}`);
|
|
41
|
+
const seeders = Array.from(new Bun.Glob("**/*").scanSync({
|
|
42
|
+
cwd: seedersPath
|
|
43
|
+
})).filter(value => (/\.(m?js|ts)$/.test(value) &&
|
|
44
|
+
!value.endsWith(".d.ts")));
|
|
45
|
+
const template = seeders.find(value => value.includes("seeder_template"));
|
|
46
|
+
if (isEmpty(template)) {
|
|
47
|
+
Logger.setContext("APP").error("Whoops, something went wrong, the seeder template not found.");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const now = Luxon.datetime.now().toFormat("yyyyMMdd");
|
|
51
|
+
const latest = Array.from(new Bun.Glob("**/*").scanSync({
|
|
52
|
+
cwd: App.Path.databasePath(seedersDirectory)
|
|
53
|
+
})).map((value) => {
|
|
54
|
+
const split = value.split("_").slice(0, 2);
|
|
55
|
+
return {
|
|
56
|
+
date: split[0],
|
|
57
|
+
count: split[1]
|
|
58
|
+
};
|
|
59
|
+
}).filter((value) => {
|
|
60
|
+
return value.date === now;
|
|
61
|
+
}).map((value) => value.count).sort().reverse()[0];
|
|
62
|
+
const counter = defineValue(parseInt(latest), 0);
|
|
63
|
+
const destination = `${seedersDirectory}/${now}_${String(counter + 1).padStart(6, "0")}_${file}.ts`;
|
|
64
|
+
await Bun.write(App.Path.databasePath(destination), await Bun.file(path.resolve(seedersPath, template)).text());
|
|
65
|
+
Logger.setContext("APP").info(`Seeder [database/${destination}] created successfully.`);
|
|
66
|
+
}
|
|
67
|
+
}
|