@take-out/postgres 0.0.41 → 0.0.42
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 +37 -22
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -104,26 +104,39 @@ await migrate({
|
|
|
104
104
|
|
|
105
105
|
## CLI
|
|
106
106
|
|
|
107
|
-
The package includes a CLI with several database utilities:
|
|
107
|
+
The package includes a CLI with several database utilities. Run with `bunx postgres` or `bun env:dev bunx postgres` (to load env vars):
|
|
108
108
|
|
|
109
109
|
```bash
|
|
110
110
|
# show help
|
|
111
|
-
|
|
111
|
+
bunx postgres --help
|
|
112
112
|
|
|
113
113
|
# connect to database with psql
|
|
114
|
-
|
|
114
|
+
bun env:dev bunx postgres psql
|
|
115
115
|
|
|
116
|
-
#
|
|
117
|
-
|
|
116
|
+
# run a query directly
|
|
117
|
+
bun env:dev bunx postgres psql --query "SELECT * FROM users LIMIT 5"
|
|
118
118
|
|
|
119
|
-
#
|
|
120
|
-
|
|
119
|
+
# create a new migration
|
|
120
|
+
bunx postgres migrate:add my-migration-name
|
|
121
121
|
|
|
122
122
|
# dump database
|
|
123
|
-
|
|
123
|
+
bun env:dev bunx postgres pg_dump > backup.sql
|
|
124
124
|
|
|
125
|
-
# sync drizzle migrations to TypeScript
|
|
126
|
-
|
|
125
|
+
# sync drizzle migrations to TypeScript wrappers
|
|
126
|
+
bunx postgres sync-drizzle
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
For migrations, use the project scripts:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
# local dev - generates and runs migrations
|
|
133
|
+
bun migrate run
|
|
134
|
+
|
|
135
|
+
# production - generates and builds
|
|
136
|
+
bun migrate build
|
|
137
|
+
|
|
138
|
+
# add a custom typescript migration
|
|
139
|
+
bun db:migrate-add my-migration-name
|
|
127
140
|
```
|
|
128
141
|
|
|
129
142
|
### CLI Configuration
|
|
@@ -136,19 +149,20 @@ The CLI uses environment variables for configuration:
|
|
|
136
149
|
|
|
137
150
|
## Migration System
|
|
138
151
|
|
|
139
|
-
|
|
152
|
+
The migration system combines Drizzle schema migrations with custom TypeScript
|
|
153
|
+
migrations. You don't need to run Drizzle commands directly.
|
|
154
|
+
|
|
155
|
+
### Schema Migrations
|
|
140
156
|
|
|
141
|
-
1. Update
|
|
142
|
-
2.
|
|
143
|
-
3. Sync to TypeScript: `db sync`
|
|
144
|
-
4. Run migrations: `db migrate`
|
|
157
|
+
1. Update `src/database/schema-public.ts` or `schema-private.ts`
|
|
158
|
+
2. Run `bun migrate run` (generates + runs migrations)
|
|
145
159
|
|
|
146
|
-
### TypeScript Migrations
|
|
160
|
+
### Custom TypeScript Migrations
|
|
147
161
|
|
|
148
|
-
For
|
|
162
|
+
For data migrations or changes that can't be expressed in schema:
|
|
149
163
|
|
|
150
164
|
```bash
|
|
151
|
-
db
|
|
165
|
+
bun db:migrate-add fix-user-data
|
|
152
166
|
```
|
|
153
167
|
|
|
154
168
|
This creates a new TypeScript file:
|
|
@@ -157,17 +171,18 @@ This creates a new TypeScript file:
|
|
|
157
171
|
import type { PoolClient } from 'pg'
|
|
158
172
|
|
|
159
173
|
export async function up(client: PoolClient) {
|
|
160
|
-
// your migration code here
|
|
161
174
|
await client.query(`
|
|
162
175
|
UPDATE users SET email = lower(email)
|
|
163
176
|
`)
|
|
164
177
|
}
|
|
165
178
|
```
|
|
166
179
|
|
|
167
|
-
###
|
|
180
|
+
### How It Works
|
|
168
181
|
|
|
169
|
-
The `
|
|
170
|
-
|
|
182
|
+
The `bun migrate build` command:
|
|
183
|
+
1. Runs `drizzle-kit generate` to create SQL migrations from schema changes
|
|
184
|
+
2. Wraps SQL migrations in TypeScript (using `?raw` imports)
|
|
185
|
+
3. Bundles all migrations into a single deployable file
|
|
171
186
|
|
|
172
187
|
```typescript
|
|
173
188
|
// migrations/0001_example.sql → migrations/0001_example.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@take-out/postgres",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@take-out/helpers": "0.0.
|
|
56
|
+
"@take-out/helpers": "0.0.42",
|
|
57
57
|
"async-retry": "^1.3.3",
|
|
58
58
|
"citty": "^0.1.6"
|
|
59
59
|
},
|