Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"permissions": {
"allow": [
"Bash(pnpm --filter @casekit/orm-cli --filter @casekit/orm-migrate test)"
]
}
}
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ name: CI
env:
DO_NOT_TRACK: 1

permissions:
contents: read
packages: read
pull-requests: write

on:
push:
branches: [main]
Expand Down Expand Up @@ -43,6 +48,7 @@ jobs:
with:
node-version-file: ".tool-versions"
cache: "pnpm"
registry-url: "https://npm.pkg.github.com"

- name: Get pnpm store directory
shell: bash
Expand All @@ -51,6 +57,8 @@ jobs:

- name: Install dependencies
run: pnpm install --frozen-lockfile
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}

- name: Run tests
run: pnpm test
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

permissions:
contents: read
packages: read
pages: write
id-token: write

Expand All @@ -27,9 +28,12 @@ jobs:
with:
node-version: 20
cache: pnpm
registry-url: "https://npm.pkg.github.com"

- name: Install dependencies
run: pnpm install
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}

- name: Build docs
run: pnpm --filter @casekit/orm-docs build
Expand Down
98 changes: 98 additions & 0 deletions .github/workflows/publish-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Publish Preview Packages

on:
workflow_dispatch:
push:
branches-ignore:
- "dependabot/**"
paths:
- "packages/**"

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v6

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: ".tool-versions"
cache: "pnpm"
registry-url: "https://npm.pkg.github.com"

- name: Install dependencies
run: pnpm install --frozen-lockfile
env:
NODE_AUTH_TOKEN: ${{ secrets.GH_PACKAGES_TOKEN }}

- name: Build packages
run: pnpm build

- name: Generate version string
id: version
run: |
BRANCH="${GITHUB_REF_NAME}"
# Sanitize branch name for npm (replace / with -)
BRANCH_SAFE=$(echo "$BRANCH" | sed 's/[^a-zA-Z0-9-]/-/g' | sed 's/--*/-/g' | sed 's/^-//' | sed 's/-$//')
SHORT_SHA="${GITHUB_SHA::7}"
VERSION="0.0.0-${BRANCH_SAFE}.${SHORT_SHA}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
echo "Publishing version: $VERSION"

- name: Update package versions
run: pnpm -r exec npm version ${{ steps.version.outputs.version }} --no-git-tag-version

- name: Publish packages
run: pnpm -r publish --access public --tag preview --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Summary
run: |
echo "## Published Packages" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Version: \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Install with:" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "pnpm add @casekit/orm@${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY

cleanup:
runs-on: ubuntu-latest
needs: publish
permissions:
packages: write
strategy:
matrix:
package:
- orm
- orm-cli
- orm-schema
- orm-config
- orm-migrate
- orm-testing
- orm-fixtures
- sql
- toolbox

steps:
- name: Delete old ${{ matrix.package }} versions
uses: actions/delete-package-versions@v5
with:
package-name: ${{ matrix.package }}
package-type: npm
min-versions-to-keep: 50
delete-only-pre-release-versions: true
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@casekit:registry=https://npm.pkg.github.com
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm add @casekit/orm @casekit/orm-cli @casekit/orm-migrate pg zod
### 1. Initialize your project

```bash
npx orm init --directory ./src/db
pnpm orm init --directory ./src/db
```

### 2. Define your models
Expand Down Expand Up @@ -69,7 +69,7 @@ export const db = orm(config);
### 4. Push schema to database

```bash
npx orm db push
pnpm orm db push
```

### 5. Query with full type safety
Expand Down
36 changes: 18 additions & 18 deletions docs/docs/cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ All commands support these options:
Initialize a new project with ORM configuration.

```bash
npx orm init [options]
pnpm orm init [options]
```

### Options
Expand All @@ -33,7 +33,7 @@ npx orm init [options]
### Example

```bash
npx orm init --directory ./src/db
pnpm orm init --directory ./src/db
```

### Generated Files
Expand All @@ -48,12 +48,12 @@ npx orm init --directory ./src/db
**DANGER** DO NOT USE THIS ON A PRODUCTION DATABASE, OR DATA LOSS MAY OCCUR.
:::

Proper migration support will come in a future release.
This command is for development only. For production environments, use [migrations](./migrations.md) instead.

Push the schema to the database, creating tables and constraints.

```bash
npx orm db push
pnpm orm db push
```

This command:
Expand All @@ -66,7 +66,7 @@ This command:
### Example

```bash
npx orm db push
pnpm orm db push
```

Output:
Expand All @@ -85,7 +85,7 @@ Pushing schemas public to database
Introspect the database and generate model files.

```bash
npx orm db pull [options]
pnpm orm db pull [options]
```

### Options
Expand All @@ -99,13 +99,13 @@ npx orm db pull [options]

```bash
# Pull from default schema
npx orm db pull
pnpm orm db pull

# Pull from specific schemas
npx orm db pull --schema public --schema audit
pnpm orm db pull --schema public --schema audit

# Force overwrite
npx orm db pull --force
pnpm orm db pull --force
```

### Generated Files
Expand Down Expand Up @@ -134,7 +134,7 @@ src/db/models/
Drop all schemas used by your models.

```bash
npx orm db drop
pnpm orm db drop
```

:::warning
Expand All @@ -144,7 +144,7 @@ This is a destructive operation that deletes all data. Use with caution.
### Example

```bash
npx orm db drop
pnpm orm db drop
```

Output:
Expand All @@ -158,7 +158,7 @@ Output:
Generate a skeleton model file.

```bash
npx orm generate model <name> [options]
pnpm orm generate model <name> [options]
```

### Arguments
Expand All @@ -176,7 +176,7 @@ npx orm generate model <name> [options]
### Example

```bash
npx orm generate model user
pnpm orm generate model user
```

Creates `src/db/models/user.ts`:
Expand All @@ -197,22 +197,22 @@ And updates `src/db/models/index.ts` to export it.

```bash
# 1. Initialize project
npx orm init --directory ./src/db
pnpm orm init --directory ./src/db

# 2. Write your models in ./src/db/models/

# 3. Push schema to database
npx orm db push
pnpm orm db push
```

### Database-First (Generate Models from Database)

```bash
# 1. Initialize project
npx orm init --directory ./src/db
pnpm orm init --directory ./src/db

# 2. Pull schema from existing database
npx orm db pull --schema public
pnpm orm db pull --schema public

# 3. Customize generated models as needed
```
Expand All @@ -221,5 +221,5 @@ npx orm db pull --schema public

```bash
# Drop and recreate
npx orm db drop && npx orm db push
pnpm orm db drop && pnpm orm db push
```
2 changes: 1 addition & 1 deletion docs/docs/cli/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ DB_PASSWORD=secret
Specify a different config file:

```bash
npx orm db push --config ./config/orm.config.ts
pnpm orm db push --config ./config/orm.config.ts
```

## Complete Example
Expand Down
Loading