Skip to content

Commit a543939

Browse files
committed
aded knex migrations
1 parent 2ebd7ed commit a543939

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

knexfile.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Update with your config settings.
2+
3+
/**
4+
* @type { Object.<string, import("knex").Knex.Config> }
5+
*/
6+
module.exports = {
7+
8+
development: {
9+
client: 'sqlite3',
10+
connection: {
11+
filename: './db/dev.db' // Path to your SQLite database file
12+
},
13+
useNullAsDefault: true, // Required for SQLite
14+
migrations: {
15+
directory: './db/migrations' // Directory for migration files
16+
},
17+
},
18+
19+
20+
// staging: {
21+
// client: 'postgresql',
22+
// connection: {
23+
// database: 'my_db',
24+
// user: 'username',
25+
// password: 'password'
26+
// },
27+
// pool: {
28+
// min: 2,
29+
// max: 10
30+
// },
31+
// migrations: {
32+
// tableName: 'knex_migrations'
33+
// }
34+
// },
35+
36+
// production: {
37+
// client: 'postgresql',
38+
// connection: {
39+
// database: 'my_db',
40+
// user: 'username',
41+
// password: 'password'
42+
// },
43+
// pool: {
44+
// min: 2,
45+
// max: 10
46+
// },
47+
// migrations: {
48+
// tableName: 'knex_migrations'
49+
// }
50+
// }
51+
52+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "reactron-base",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"main": "dist/main/index.js",
55
"scripts": {
66
"build:main": "tsc src/main/index.ts src/main/preload.ts --outDir dist/main",

readme.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ A: Use the provided seeding and resetting methods in `src/main` or dedicated scr
194194

195195
A: Refer to the [Electron Documentation](https://www.electronjs.org/docs) and the [Vite Documentation](https://vitejs.dev/) for more information.
196196

197+
Here's the updated section for your `README.md` file, including instructions for running Knex migrations:
198+
199+
---
200+
197201
## 🛠️ Seeding and Resetting the Database
198202

199203
### Seeding the Database
@@ -242,6 +246,50 @@ Run the script to reset the database:
242246
npx ts-node src/main/seed.ts
243247
```
244248

249+
### Running Knex Migrations
250+
251+
To manage your database schema with Knex, use migrations. Follow these steps:
252+
253+
1. **Create a Migration File**
254+
255+
Create a new migration file to define schema changes:
256+
257+
```bash
258+
npx knex migrate:make creating_schema
259+
```
260+
261+
This will generate a file like `YYYYMMDDHHMMSS_creating_schema.js` inside the `migrations` directory.
262+
263+
2. **Define Your Schema in the Migration File**
264+
265+
Open the generated migration file and define your schema:
266+
267+
```javascript
268+
// migrations/YYYYMMDDHHMMSS_creating_schema.js
269+
exports.up = function (knex) {
270+
return knex.schema.createTable('example_table', (table) => {
271+
table.increments('id').primary();
272+
table.string('name').notNullable();
273+
table.timestamps(true, true);
274+
});
275+
};
276+
277+
exports.down = function (knex) {
278+
return knex.schema.dropTable('example_table');
279+
};
280+
```
281+
282+
3. **Run the Migrations**
283+
284+
Apply the migrations to your database:
285+
286+
```bash
287+
npx knex migrate:latest
288+
```
289+
290+
This command will execute all pending migrations and update your database schema.
291+
292+
245293
## 🚀 Upcoming Features
246294

247295
- **Enhanced ORM Integration**: Research and integrate an ORM (Object-Relational Mapping) library for improved database interactions. Options include [TypeORM](https://typeorm.io/), [Sequelize](https://sequelize.org/), or creating a custom base model for better data management.

0 commit comments

Comments
 (0)