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
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# EditorConfig helps maintain consistent coding styles
# https://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[Makefile]
indent_style = tab
137 changes: 137 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18, 20, 22]

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run linter
run: npm run lint

- name: Run type check
run: npm run typecheck

- name: Run tests
run: npm test

- name: Build
run: npm run build

publish-npm:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Check if version changed
id: version
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
NPM_VERSION=$(npm view supabase-sql-dev-runner version 2>/dev/null || echo "0.0.0")
if [ "$PACKAGE_VERSION" != "$NPM_VERSION" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Version changed from $NPM_VERSION to $PACKAGE_VERSION"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "Version unchanged at $PACKAGE_VERSION"
fi

- name: Publish to npm
if: steps.version.outputs.changed == 'true'
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

publish-github:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
registry-url: 'https://npm.pkg.github.com'
scope: '@4riel'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Check if version changed on GitHub Packages
id: version
run: |
PACKAGE_VERSION=$(node -p "require('./package.json').version")
# Try to get version from GitHub Packages
GPR_VERSION=$(npm view @4riel/supabase-sql-dev-runner version --registry=https://npm.pkg.github.com 2>/dev/null || echo "0.0.0")
if [ "$PACKAGE_VERSION" != "$GPR_VERSION" ]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "Version changed from $GPR_VERSION to $PACKAGE_VERSION"
else
echo "changed=false" >> $GITHUB_OUTPUT
echo "Version unchanged at $PACKAGE_VERSION"
fi
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to GitHub Packages
if: steps.version.outputs.changed == 'true'
run: |
# Create a scoped package.json for GitHub Packages
node -e "
const pkg = require('./package.json');
pkg.name = '@4riel/supabase-sql-dev-runner';
pkg.publishConfig = { registry: 'https://npm.pkg.github.com' };
require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
"
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70 changes: 70 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Dependencies
node_modules/

# Build output
dist/

# SQL files directory (user-generated)
sql/

# Logs
logs/
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Environment variables
.env
.env.local
.env.*.local
.env.development
.env.test
.env.production

# IDE and editors
.idea/
.vscode/
*.swp
*.swo
*.sublime-workspace
*.sublime-project
.project
.classpath
.settings/

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
desktop.ini

# Test coverage
coverage/
.nyc_output/

# Package manager locks (keep package-lock.json for npm)
yarn.lock
pnpm-lock.yaml

# Temporary files
*.tmp
*.temp
*.bak
*~

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Tarball from npm pack
*.tgz
31 changes: 31 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Source files (we ship compiled code)
src/
tests/
scripts/

# Config files
tsconfig*.json
vitest.config.ts
eslint.config.js
.eslintrc*
.prettierrc
.prettierrc*
.editorconfig
.nvmrc

# Development files
.gitignore
.github/
CHANGELOG.md

# Misc
*.log
coverage/
.env*

# User-generated directories
sql/
logs/

# AI assistant context file
CLAUDE.md
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 100,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
}
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2025-12-10

### Added

- Initial release
- Comprehensive test suite with 165 tests across 8 test files
- Test coverage for: CLI parsing, connection handling, logging, file scanning, SQL execution, and integration flows
- Sequential SQL file execution with alphabetical ordering
- Transaction safety with automatic rollback on errors
- Savepoint support for granular rollback per file
- Human confirmation prompt before execution (configurable)
- CLI tool with extensive options (`sql-runner`, `supabase-sql-runner`)
- Programmatic API with `SqlRunner` class and `runSqlScripts` convenience function
- Dual module support (ESM and CommonJS)
- Full TypeScript type definitions
- SSL enabled by default for secure connections
- Password masking in logs
- Verbose mode for detailed output
- Dry run mode to preview execution
- File filtering with `--only` and `--skip` options
- Environment file loading (`.env` support)
- Execution logging to file
- Progress callbacks (`onBeforeFile`, `onAfterFile`, `onComplete`, `onError`)
- SQL NOTICE message handling via `onNotice` callback
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Ariel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading