nexusql 0.1.0
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/README.md +147 -0
- package/bin/nexusql.js +2 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +999 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +256 -0
- package/dist/index.js +909 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# nexusql
|
|
2
|
+
|
|
3
|
+
Database migration toolkit for PostgreSQL with DBML schema support.
|
|
4
|
+
|
|
5
|
+
Generate migration SQL by comparing your DBML schema against your live database using [migra](https://github.com/djrobstep/migra).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g nexusql
|
|
11
|
+
# or
|
|
12
|
+
npx nexusql
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Prerequisites
|
|
16
|
+
|
|
17
|
+
You need to have [migra](https://github.com/djrobstep/migra) installed:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install migra
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
1. Initialize your project:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
nexusql init
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
2. Set your database URL in `.env`:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
DATABASE_URL=postgres://user:password@localhost:5432/mydb
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
3. Create your schema in `schema.dbml`:
|
|
38
|
+
|
|
39
|
+
```dbml
|
|
40
|
+
Table users {
|
|
41
|
+
id uuid [pk, default: `uuid_generate_v4()`]
|
|
42
|
+
email varchar(255) [unique, not null]
|
|
43
|
+
name varchar(255)
|
|
44
|
+
created_at timestamp [default: `now()`]
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
4. Generate and apply migrations:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
nexusql migrate
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Commands
|
|
55
|
+
|
|
56
|
+
| Command | Description |
|
|
57
|
+
|---------|-------------|
|
|
58
|
+
| `nexusql init` | Initialize configuration and directories |
|
|
59
|
+
| `nexusql gen` | Generate migration SQL from DBML schema |
|
|
60
|
+
| `nexusql migrate` | Interactive: generate → create file → apply |
|
|
61
|
+
| `nexusql up` | Apply all pending migrations |
|
|
62
|
+
| `nexusql status` | Show migration status |
|
|
63
|
+
| `nexusql mark-applied <version>` | Mark migration as applied without running |
|
|
64
|
+
|
|
65
|
+
### `nexusql gen`
|
|
66
|
+
|
|
67
|
+
Generate migration SQL by diffing your current database against the DBML schema.
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
nexusql gen # Output to stdout
|
|
71
|
+
nexusql gen -o migration.sql # Write to file
|
|
72
|
+
nexusql gen -v # Verbose output
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### `nexusql migrate`
|
|
76
|
+
|
|
77
|
+
Interactive workflow that combines generation and file creation:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
nexusql migrate # Interactive mode
|
|
81
|
+
nexusql migrate -n "add_users" # Specify migration name
|
|
82
|
+
nexusql migrate -a # Apply immediately
|
|
83
|
+
nexusql migrate -y # Skip confirmations
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### `nexusql up`
|
|
87
|
+
|
|
88
|
+
Apply all pending migrations:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
nexusql up
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### `nexusql status`
|
|
95
|
+
|
|
96
|
+
Show which migrations have been applied and which are pending:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
nexusql status
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Configuration
|
|
103
|
+
|
|
104
|
+
Create `nexusql.config.js` in your project root:
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
export default {
|
|
108
|
+
// Path to DBML schema file
|
|
109
|
+
schema: './schema.dbml',
|
|
110
|
+
|
|
111
|
+
// Migration files directory
|
|
112
|
+
migrations: './db/migrations',
|
|
113
|
+
|
|
114
|
+
// PostgreSQL extensions to install in temp database
|
|
115
|
+
extensions: ['uuid-ossp', 'vector'],
|
|
116
|
+
};
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Environment variables:
|
|
120
|
+
- `DATABASE_URL` - PostgreSQL connection string
|
|
121
|
+
|
|
122
|
+
## Migration Format
|
|
123
|
+
|
|
124
|
+
Migrations use dbmate-compatible format:
|
|
125
|
+
|
|
126
|
+
```sql
|
|
127
|
+
-- migrate:up
|
|
128
|
+
CREATE TABLE users (
|
|
129
|
+
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
|
|
130
|
+
email varchar(255) UNIQUE NOT NULL
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
-- migrate:down
|
|
134
|
+
DROP TABLE users;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## How It Works
|
|
138
|
+
|
|
139
|
+
1. Reads your DBML schema and converts it to SQL
|
|
140
|
+
2. Creates a temporary database and loads the target schema
|
|
141
|
+
3. Uses `migra` to generate the diff between current and target
|
|
142
|
+
4. Creates a timestamped migration file
|
|
143
|
+
5. Tracks applied migrations in `schema_migrations` table
|
|
144
|
+
|
|
145
|
+
## License
|
|
146
|
+
|
|
147
|
+
MIT
|
package/bin/nexusql.js
ADDED
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|