mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-06-04 06:53:04 +00:00
Compare commits
4 Commits
cmd/webica
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e86b7c4374 | ||
|
|
0e7c22ec2c | ||
|
|
7d6a01c200 | ||
|
|
946a340423 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -18,15 +18,21 @@ install-*.ps1
|
||||
*.env
|
||||
.env
|
||||
!example.env
|
||||
LOCAL.md
|
||||
|
||||
# caches
|
||||
_cache/
|
||||
node_modules/
|
||||
|
||||
# temporary & backup files
|
||||
agents/
|
||||
.*.sw*
|
||||
*.bak
|
||||
*.bak.*
|
||||
tmp
|
||||
*.tmp
|
||||
tmp.*
|
||||
*.tmp.*
|
||||
|
||||
# agent session files
|
||||
agents/
|
||||
|
||||
128
basecamp/README.md
Normal file
128
basecamp/README.md
Normal file
@@ -0,0 +1,128 @@
|
||||
---
|
||||
title: basecamp
|
||||
homepage: https://github.com/basecamp/basecamp-cli
|
||||
tagline: |
|
||||
basecamp: CLI for Basecamp 3 — manage projects, todos, messages, cards, and more from the terminal.
|
||||
---
|
||||
|
||||
To update or switch versions, run `webi basecamp@stable` (or `@v0.7`,
|
||||
`@beta`, etc).
|
||||
|
||||
### Files
|
||||
|
||||
These are the files / directories that are created and/or modified with this
|
||||
install:
|
||||
|
||||
```text
|
||||
~/.config/envman/PATH.env
|
||||
~/.local/bin/basecamp
|
||||
~/.local/opt/basecamp-VERSION/bin/basecamp
|
||||
~/.local/opt/basecamp-VERSION/completions/
|
||||
```
|
||||
|
||||
## Cheat Sheet
|
||||
|
||||
> `basecamp` is the official CLI for Basecamp 3. It provides full API coverage
|
||||
> for projects, todos, messages, cards, schedule, files, and more — all from the
|
||||
> command line.
|
||||
|
||||
### How to authenticate
|
||||
|
||||
```sh
|
||||
basecamp auth login
|
||||
```
|
||||
|
||||
For headless environments (CI, remote servers):
|
||||
|
||||
```sh
|
||||
basecamp auth login --device-code
|
||||
```
|
||||
|
||||
Check auth status:
|
||||
|
||||
```sh
|
||||
basecamp auth status
|
||||
```
|
||||
|
||||
### How to list projects and todos
|
||||
|
||||
```sh
|
||||
basecamp projects list --md
|
||||
|
||||
basecamp todos list --assignee me --in PROJECT_ID --md
|
||||
```
|
||||
|
||||
Cross-project view of your assigned work:
|
||||
|
||||
```sh
|
||||
basecamp assignments --md
|
||||
```
|
||||
|
||||
### How to create and complete todos
|
||||
|
||||
```sh
|
||||
basecamp todo "Write release notes" --in PROJECT_ID --list TODOLIST_ID --assignee me --due tomorrow
|
||||
|
||||
basecamp done TODO_ID
|
||||
```
|
||||
|
||||
### How to post a message or comment
|
||||
|
||||
```sh
|
||||
basecamp message "Sprint Update" "Shipped v2.1 to production." --in PROJECT_ID
|
||||
|
||||
basecamp comment RECORDING_ID "Looks good." --in PROJECT_ID
|
||||
```
|
||||
|
||||
### How to move cards through a workflow
|
||||
|
||||
```sh
|
||||
basecamp cards columns --in PROJECT_ID --md
|
||||
|
||||
basecamp cards move CARD_ID --to COLUMN_ID --in PROJECT_ID
|
||||
```
|
||||
|
||||
### How to set up per-project defaults
|
||||
|
||||
Create `.basecamp/config.json` in your repo (commit it):
|
||||
|
||||
```json
|
||||
{
|
||||
"project_id": "12345",
|
||||
"todolist_id": "67890"
|
||||
}
|
||||
```
|
||||
|
||||
Then trust it once:
|
||||
|
||||
```sh
|
||||
basecamp config trust
|
||||
```
|
||||
|
||||
After that, you can omit `--in` for most commands in that repo.
|
||||
|
||||
### Shell completions
|
||||
|
||||
Completions for bash, fish, and zsh ship with the installer. Find them at:
|
||||
|
||||
```text
|
||||
~/.local/opt/basecamp-VERSION/completions/
|
||||
```
|
||||
|
||||
Bash:
|
||||
|
||||
```sh
|
||||
echo "source ~/.local/opt/basecamp-VERSION/completions/basecamp.bash" >> ~/.bashrc
|
||||
```
|
||||
|
||||
Fish:
|
||||
|
||||
```sh
|
||||
ln -s ~/.local/opt/basecamp-VERSION/completions/basecamp.fish ~/.config/fish/completions/
|
||||
```
|
||||
|
||||
Zsh:
|
||||
|
||||
```sh
|
||||
echo "fpath+=( ~/.local/opt/basecamp-VERSION/completions )" >> ~/.zshrc
|
||||
```
|
||||
46
basecamp/install.ps1
Normal file
46
basecamp/install.ps1
Normal file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
$pkg_cmd_name = "basecamp"
|
||||
|
||||
$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\basecamp.exe"
|
||||
$pkg_dst = "$pkg_dst_cmd"
|
||||
|
||||
$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\basecamp-v$Env:WEBI_VERSION\bin\basecamp.exe"
|
||||
$pkg_src_bin = "$Env:USERPROFILE\.local\opt\basecamp-v$Env:WEBI_VERSION\bin"
|
||||
$pkg_src_dir = "$Env:USERPROFILE\.local\opt\basecamp-v$Env:WEBI_VERSION"
|
||||
$pkg_src = "$pkg_src_cmd"
|
||||
|
||||
New-Item "$Env:USERPROFILE\Downloads\webi" -ItemType Directory -Force | Out-Null
|
||||
$pkg_download = "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE"
|
||||
|
||||
if (!(Test-Path -Path "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE")) {
|
||||
Write-Output "Downloading basecamp from $Env:WEBI_PKG_URL to $pkg_download"
|
||||
& curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
|
||||
& Move-Item "$pkg_download.part" "$pkg_download"
|
||||
}
|
||||
|
||||
if (!(Test-Path -Path "$pkg_src_cmd")) {
|
||||
Write-Output "Installing basecamp"
|
||||
|
||||
Push-Location .local\tmp
|
||||
|
||||
Remove-Item -Path ".\basecamp-*" -Recurse -ErrorAction Ignore
|
||||
Remove-Item -Path ".\basecamp.exe" -Recurse -ErrorAction Ignore
|
||||
|
||||
Write-Output "Unpacking $pkg_download"
|
||||
& tar xf "$pkg_download"
|
||||
|
||||
New-Item "$pkg_src_bin" -ItemType Directory -Force | Out-Null
|
||||
Move-Item -Path ".\basecamp.exe" -Destination "$pkg_src_bin"
|
||||
|
||||
New-Item "$pkg_src_dir\completions" -ItemType Directory -Force | Out-Null
|
||||
if (Test-Path -Path ".\completions") {
|
||||
Copy-Item -Path ".\completions\*" -Destination "$pkg_src_dir\completions" -Recurse
|
||||
}
|
||||
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
Write-Output "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
|
||||
Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore | Out-Null
|
||||
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
|
||||
44
basecamp/install.sh
Normal file
44
basecamp/install.sh
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
__init_basecamp() {
|
||||
pkg_cmd_name="basecamp"
|
||||
|
||||
pkg_src_dir="$HOME/.local/opt/basecamp-v$WEBI_VERSION"
|
||||
pkg_src_cmd="$pkg_src_dir/bin/basecamp"
|
||||
pkg_src="$pkg_src_cmd"
|
||||
|
||||
pkg_dst_cmd="$HOME/.local/bin/basecamp"
|
||||
pkg_dst="$pkg_dst_cmd"
|
||||
|
||||
pkg_install() {
|
||||
mkdir -p "$(dirname "$pkg_src_cmd")"
|
||||
mkdir -p "$pkg_src_dir/completions"
|
||||
|
||||
if test -f ./basecamp; then
|
||||
mv ./basecamp "$pkg_src_cmd"
|
||||
elif test -e ./basecamp-*/basecamp; then
|
||||
mv ./basecamp-*/basecamp "$pkg_src_cmd"
|
||||
elif test -e ./basecamp-*; then
|
||||
mv ./basecamp-* "$pkg_src_cmd"
|
||||
else
|
||||
echo >&2 "failed to find 'basecamp' executable"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if test -d ./completions; then
|
||||
cp -a ./completions/. "$pkg_src_dir/completions/"
|
||||
fi
|
||||
}
|
||||
|
||||
pkg_get_current_version() {
|
||||
basecamp --version 2> /dev/null |
|
||||
head -n 1 |
|
||||
cut -d' ' -f3
|
||||
}
|
||||
}
|
||||
|
||||
__init_basecamp
|
||||
2
basecamp/releases.conf
Normal file
2
basecamp/releases.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
github_releases = basecamp/basecamp-cli
|
||||
exclude = .bundle .txt
|
||||
188
brew/install.sh
188
brew/install.sh
@@ -4,73 +4,143 @@ set -e
|
||||
set -u
|
||||
|
||||
_install_brew() {
|
||||
# Straight from https://brew.sh
|
||||
#/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
|
||||
# Straight from https://brew.sh
|
||||
#/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
|
||||
if test "Darwin" = "$(uname -s)"; then
|
||||
needs_xcode="$(/usr/bin/xcode-select -p > /dev/null 2> /dev/null || echo "true")"
|
||||
if test -n "${needs_xcode}"; then
|
||||
echo ""
|
||||
echo ""
|
||||
echo "ERROR: Run this command to install XCode Command Line Tools first:"
|
||||
echo ""
|
||||
echo " xcode-select --install"
|
||||
echo ""
|
||||
echo "After the install, close this terminal, open a new one, and try again."
|
||||
echo ""
|
||||
fi
|
||||
else
|
||||
if ! command -v gcc > /dev/null; then
|
||||
echo >&2 "Warning: to install 'gcc' et al on Linux use the built-in package manager."
|
||||
echo >&2 " For example, try: sudo apt install -y build-essential"
|
||||
fi
|
||||
if ! command -v git > /dev/null; then
|
||||
echo >&2 "Error: to install 'git' on Linux use the built-in package manager."
|
||||
echo >&2 " For example, try: sudo apt install -y git"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
if test "Darwin" = "$(uname -s)"; then
|
||||
needs_xcode="$(/usr/bin/xcode-select -p > /dev/null 2> /dev/null || echo "true")"
|
||||
if test -n "${needs_xcode}"; then
|
||||
echo ""
|
||||
echo ""
|
||||
echo "ERROR: Run this command to install XCode Command Line Tools first:"
|
||||
echo ""
|
||||
echo " xcode-select --install"
|
||||
echo ""
|
||||
echo "After the install, close this terminal, open a new one, and try again."
|
||||
echo ""
|
||||
fi
|
||||
else
|
||||
if ! command -v gcc > /dev/null; then
|
||||
echo >&2 "Warning: to install 'gcc' et al on Linux use the built-in package manager."
|
||||
echo >&2 " For example, try: sudo apt install -y build-essential"
|
||||
fi
|
||||
if ! command -v git > /dev/null; then
|
||||
echo >&2 "Error: to install 'git' on Linux use the built-in package manager."
|
||||
echo >&2 " For example, try: sudo apt install -y git"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# From Straight from https://brew.sh
|
||||
if ! test -d "$HOME/.local/opt/brew"; then
|
||||
echo "Installing to '$HOME/.local/opt/brew'"
|
||||
echo ""
|
||||
echo "If you prefer to have brew installed to '/usr/local' cancel now and do the following:"
|
||||
echo " rm -rf '$HOME/.local/opt/brew'"
|
||||
# shellcheck disable=2016
|
||||
echo ' /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"'
|
||||
echo ""
|
||||
sleep 3
|
||||
git clone --depth=1 https://github.com/Homebrew/brew "$HOME/.local/opt/brew"
|
||||
fi
|
||||
# From Straight from https://brew.sh
|
||||
if ! test -d "$HOME/.local/opt/brew"; then
|
||||
echo "Installing to '$HOME/.local/opt/brew'"
|
||||
echo ""
|
||||
echo "If you prefer to have brew installed to '/usr/local' cancel now and do the following:"
|
||||
echo " rm -rf '$HOME/.local/opt/brew'"
|
||||
# shellcheck disable=2016
|
||||
echo ' /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
|
||||
echo ""
|
||||
sleep 3
|
||||
#mkdir -p "$HOME/.local/opt/brew"
|
||||
#curl -fsSL https://github.com/Homebrew/brew/tarball/main |
|
||||
# tar xz --strip-components 1 -C "$HOME/.local/opt/brew"
|
||||
git clone --depth 3 https://github.com/Homebrew/brew "$HOME/.local/opt/brew"
|
||||
fi
|
||||
|
||||
rm -rf "$HOME/.local/bin/brew-update-service-install"
|
||||
webi_download \
|
||||
"$WEBI_HOST/packages/brew/brew-update-service-install" \
|
||||
"$HOME/.local/bin/brew-update-service-install" \
|
||||
brew-update-service-install
|
||||
chmod a+x "$HOME/.local/bin/brew-update-service-install"
|
||||
my_shellenv="$("$HOME/.local/opt/brew/bin/brew" shellenv)"
|
||||
eval "${my_shellenv}"
|
||||
chmod -R go-w "$(brew --prefix)/share/zsh" 2> /dev/null || true
|
||||
|
||||
webi_path_add "$HOME/.local/opt/brew/bin"
|
||||
export PATH="$HOME/.local/opt/brew/bin:$PATH"
|
||||
rm -rf "$HOME/.local/bin/brew-update-service-install"
|
||||
webi_download \
|
||||
"$WEBI_HOST/packages/brew/brew-update-service-install" \
|
||||
"$HOME/.local/bin/brew-update-service-install" \
|
||||
brew-update-service-install
|
||||
chmod a+x "$HOME/.local/bin/brew-update-service-install"
|
||||
|
||||
echo "Updating brew..."
|
||||
brew update
|
||||
webi_path_add "$HOME/.local/opt/brew/bin"
|
||||
webi_path_add "$HOME/.local/opt/brew/sbin"
|
||||
|
||||
webi_path_add "$HOME/.local/opt/brew/sbin"
|
||||
export PATH="$HOME/.local/opt/brew/sbin:$PATH"
|
||||
fn_brew_shell_integrate_bash
|
||||
fn_brew_shell_integrate_zsh
|
||||
fn_brew_shell_integrate_fish
|
||||
|
||||
echo "Installed 'brew' to '$HOME/.local/opt/brew'"
|
||||
echo ""
|
||||
echo "If you prefer to have brew installed to '/usr/local' do the following:"
|
||||
echo " mv '$HOME/.local/opt/brew' '$HOME/.local/opt/brew.$(date '+%F_%H-%M-%S').bak'"
|
||||
# shellcheck disable=2016
|
||||
echo ' /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"'
|
||||
echo ""
|
||||
echo "Installed 'brew' to '$HOME/.local/opt/brew'"
|
||||
echo ""
|
||||
echo "If you prefer to have brew installed to '/usr/local' do the following:"
|
||||
echo " mv '$HOME/.local/opt/brew' '$HOME/.local/opt/brew.$(date '+%F_%H-%M-%S').bak'"
|
||||
# shellcheck disable=2016
|
||||
echo ' /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
|
||||
echo ""
|
||||
|
||||
echo "To register 'brew update' as a hourly system service:"
|
||||
echo " brew-update-service-install"
|
||||
echo ""
|
||||
echo "To register 'brew update' as a hourly system service:"
|
||||
echo " brew-update-service-install"
|
||||
echo ""
|
||||
}
|
||||
|
||||
fn_brew_shell_integrate_bash() {
|
||||
if ! command -v bash > /dev/null; then
|
||||
return 0
|
||||
fi
|
||||
if ! test -e ~/.bashrc && ! test -e ~/.bash_history; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
touch -a ~/.bashrc
|
||||
if grep -q 'brew shellenv' ~/.bashrc; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo >&2 " Edit ~/.bashrc to init brew"
|
||||
# shellcheck disable=SC2016
|
||||
{
|
||||
echo ''
|
||||
echo '# Generated by Webi. Do not edit.'
|
||||
echo 'eval "$('"$HOME/.local/opt/brew/bin/brew"' shellenv)"'
|
||||
} >> ~/.bashrc
|
||||
}
|
||||
|
||||
fn_brew_shell_integrate_zsh() {
|
||||
if ! command -v zsh > /dev/null; then
|
||||
return 0
|
||||
fi
|
||||
if ! test -e ~/.zshrc &&
|
||||
! test -e ~/.zsh_sessions &&
|
||||
! test -e ~/.zsh_history; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
touch -a ~/.zshrc
|
||||
if grep -q 'brew shellenv' ~/.zshrc; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo >&2 " Edit ~/.zshrc to init brew"
|
||||
# shellcheck disable=SC2016
|
||||
{
|
||||
echo ''
|
||||
echo '# Generated by Webi. Do not edit.'
|
||||
echo 'eval "$('"$HOME/.local/opt/brew/bin/brew"' shellenv)"'
|
||||
} >> ~/.zshrc
|
||||
}
|
||||
|
||||
fn_brew_shell_integrate_fish() {
|
||||
if ! command -v fish > /dev/null; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
mkdir -p ~/.config/fish
|
||||
touch -a ~/.config/fish/config.fish
|
||||
if grep -q 'brew shellenv' ~/.config/fish/config.fish; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo >&2 " Edit ~/.config/fish/config.fish to init brew"
|
||||
{
|
||||
echo ''
|
||||
echo '# Generated by Webi. Do not edit.'
|
||||
echo "$HOME/.local/opt/brew/bin/brew shellenv | source"
|
||||
} >> ~/.config/fish/config.fish
|
||||
}
|
||||
|
||||
_install_brew
|
||||
|
||||
118
sql-migrate/README.md
Normal file
118
sql-migrate/README.md
Normal file
@@ -0,0 +1,118 @@
|
||||
---
|
||||
title: sql-migrate
|
||||
homepage: https://github.com/therootcompany/golib/tree/main/cmd/sql-migrate
|
||||
tagline: |
|
||||
sql-migrate: A lightweight, feature-branch-friendly SQL migrator.
|
||||
---
|
||||
|
||||
To update or switch versions, run `webi sql-migrate@stable` (or `@v2`, `@beta`,
|
||||
etc).
|
||||
|
||||
### Files
|
||||
|
||||
These are the files that are created and/or modified with this installer:
|
||||
|
||||
```text
|
||||
~/.config/envman/PATH.env
|
||||
~/.local/bin/sql-migrate
|
||||
~/.local/opt/sql-migrate-VERSION/bin/sql-migrate
|
||||
|
||||
<PROJECT-DIR>/migrations.log
|
||||
<PROJECT-DIR>/sql/migrations/<yyyy-mm-dd>-<number>_<name>.<up|down>.sql
|
||||
```
|
||||
|
||||
## Cheat Sheet
|
||||
|
||||
> `sql-migrate` is a lightweight migration tool that gets out of your way - it
|
||||
> works with your existing SQL tools and allows working with distinct sets of
|
||||
> migrations, such as is typical in feature branches.
|
||||
|
||||
### How to use sql-migrate
|
||||
|
||||
Migration commands output a POSIX shell script which should be run with `sh`.
|
||||
|
||||
`init`, `sync`, `up`, `down`, `list`, `status`
|
||||
|
||||
```sh
|
||||
# Initialize a migration directory
|
||||
sql-migrate -d ./sql/migrations/ init --sql-command psql
|
||||
|
||||
# Export ENVs for your database
|
||||
export PG_URL='postgres://user:pass@example.com/dbname?sslmode=require&sslnegotiation=direct'
|
||||
|
||||
# Create a new migration (auto-generates up/down pair with incrementing number)
|
||||
sql-migrate -d ./sql/migrations/ create add-users-table
|
||||
|
||||
# SELECT and log existing migrations
|
||||
sql-migrate -d ./sql/migrations/ sync | sh
|
||||
|
||||
# Run all pending migrations up
|
||||
sql-migrate -d ./sql/migrations/ up | sh
|
||||
|
||||
# Run 3 migrations up
|
||||
sql-migrate -d ./sql/migrations/ up 3 | sh
|
||||
|
||||
# Run 1 migration down (roll back)
|
||||
sql-migrate -d ./sql/migrations/ down | sh
|
||||
|
||||
# Run 2 migrations down
|
||||
sql-migrate -d ./sql/migrations/ down 2 | sh
|
||||
|
||||
# List all migrations
|
||||
sql-migrate -d ./sql/migrations/ list
|
||||
|
||||
# See which migrations have been applied
|
||||
sql-migrate -d ./sql/migrations/ status
|
||||
```
|
||||
|
||||
### Migration directory layout
|
||||
|
||||
Migrations follow the naming format
|
||||
`<yyyy-mm-dd>-<number>_<name>.<up|down>.sql`:
|
||||
|
||||
```text
|
||||
sql/
|
||||
├── migrations.log # transaction log (auto-managed)
|
||||
└── migrations/
|
||||
├── 0001-01-01-001000_init-migrations.up.sql # generated by 'init' (has config vars)
|
||||
├── 2021-02-03-001000_init-app.up.sql
|
||||
├── 2021-02-03-001000_init-app.down.sql
|
||||
├── 2021-02-03-002000_add-products.up.sql
|
||||
├── 2021-02-03-002000_add-products.down.sql
|
||||
└── 2021-02-03-003000_add-customers.up.sql
|
||||
```
|
||||
|
||||
The initial `0001-01-01-001000_init-migrations.up.sql` migration contains
|
||||
configuration variables:
|
||||
|
||||
```sql
|
||||
-- migrations_log: ./sql/migrations.log
|
||||
-- sql_command: psql "$PG_URL" -v ON_ERROR_STOP=on --no-align --tuples-only --file %s
|
||||
```
|
||||
|
||||
Environment variables by database:
|
||||
|
||||
- PostgreSQL: `PG_URL` (auth url), `PGOPTIONS` (to set `schema` and other
|
||||
specific options)
|
||||
- SQLite3: `SQLITE_PATH`
|
||||
- SQL Server: `SQLCMDSERVER`, `SQLCMDDATABASE`, `SQLCMDUSER`, `SQLCMDPASSWORD`
|
||||
- MySQL / MariaDB: `MY_CNF` (path to `my.cnf`, containing credentials)
|
||||
|
||||
### Database client compatibility
|
||||
|
||||
The `--sql-command` flag tells sql-migrate how to talk to your database:
|
||||
|
||||
```sh
|
||||
sql-migrate -d ./sql/migrations/ init --sql-command psql
|
||||
```
|
||||
|
||||
The following clients are known and will have the correct options applied:
|
||||
|
||||
- psql (PostgreSQL)
|
||||
- sqlite3
|
||||
- sqlcmd (mssql / Microsoft SQL Server)
|
||||
- mariadb / mysql
|
||||
|
||||
Since the migrations run via shell commands, you can make `sql-migrate`
|
||||
compatible with any SQL client by setting `sql_command` in
|
||||
`migrations/0001-01-01-001000_init-migrations.up.sql`.
|
||||
78
sql-migrate/SKILL.md
Normal file
78
sql-migrate/SKILL.md
Normal file
@@ -0,0 +1,78 @@
|
||||
---
|
||||
name: sql-migrate
|
||||
description:
|
||||
Manage SQL database migrations as plain .sql files with a transaction log. Use
|
||||
when asked about sql-migrate, database migrations, or how to set up migration
|
||||
tooling.
|
||||
---
|
||||
|
||||
# sql-migrate (CLI)
|
||||
|
||||
The agent skill is embedded in the help output.
|
||||
|
||||
Run `sql-migrate --help` use its output to guide usage decisions.
|
||||
|
||||
The `up`, `down`, and `sync` subcommands produce POSIX shell scripts - pipe them
|
||||
to `sh` to run.
|
||||
|
||||
## Migration layout
|
||||
|
||||
Migrations follow the naming format
|
||||
`<yyyy-mm-dd>-<number>_<name>.<up|down>.sql`:
|
||||
|
||||
```
|
||||
sql/
|
||||
├── migrations.log # transaction log (auto-managed)
|
||||
└── migrations/
|
||||
├── 0001-01-01-001000_init-migrations.up.sql # generated by 'init'
|
||||
├── 2021-02-03-001000_init-app.up.sql
|
||||
├── 2021-02-03-001000_init-app.down.sql
|
||||
└── ...
|
||||
```
|
||||
|
||||
The initial migration file contains configuration variables:
|
||||
|
||||
```sql
|
||||
-- migrations_log: ./sql/migrations.log
|
||||
-- sql_command: psql "$PG_URL" -v ON_ERROR_STOP=on --no-align --tuples-only --file %s
|
||||
```
|
||||
|
||||
## Migration file structure
|
||||
|
||||
The migration files contain their own management, including a randomly-generated
|
||||
id:
|
||||
|
||||
```sql
|
||||
-- change_me (up)
|
||||
SELECT 'place your UP migration here';
|
||||
|
||||
-- leave this as the last line
|
||||
INSERT INTO _migrations (name, id) VALUES ('2026-05-27-002000_change_me', 'e22295e5');
|
||||
```
|
||||
|
||||
## Environment variables by database
|
||||
|
||||
- PostgreSQL: `PG_URL` (auth URL), `PGOPTIONS` (set `schema` and other options)
|
||||
- SQLite3: `SQLITE_PATH`
|
||||
- SQL Server: `SQLCMDSERVER`, `SQLCMDDATABASE`, `SQLCMDUSER`, `SQLCMDPASSWORD`
|
||||
- MySQL / MariaDB: `MY_CNF` (path to `my.cnf` containing credentials)
|
||||
|
||||
## SQL client extensibility
|
||||
|
||||
The `--sql-command` flag tells sql-migrate how to talk to your database. Known
|
||||
clients (`psql`, `sqlite3`, `sqlcmd`, `mariadb`/`mysql`) have correct options
|
||||
applied automatically. Since migrations run via shell commands, you can make
|
||||
sql-migrate compatible with any SQL client by setting `sql_command` in the init
|
||||
migration file.
|
||||
|
||||
# sqlmigrate (Go module)
|
||||
|
||||
See `go doc` for each independent module (golib is a monorepo):
|
||||
|
||||
- `github.com/therootcompany/golib/database/sqlmigrate/v2`
|
||||
- `github.com/therootcompany/golib/database/sqlmigrate/pgmigrate`
|
||||
- `github.com/therootcompany/golib/database/sqlmigrate/litemigrate`
|
||||
- `github.com/therootcompany/golib/database/sqlmigrate/msmigrate`
|
||||
- `github.com/therootcompany/golib/database/sqlmigrate/mymigrate`
|
||||
|
||||
DO NOT search the parent golib module.
|
||||
47
sql-migrate/install.ps1
Normal file
47
sql-migrate/install.ps1
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env pwsh
|
||||
|
||||
######################
|
||||
# Install sql-migrate #
|
||||
######################
|
||||
|
||||
$pkg_cmd_name = "sql-migrate"
|
||||
|
||||
$pkg_dst_cmd = "$Env:USERPROFILE\.local\bin\sql-migrate.exe"
|
||||
$pkg_dst = "$pkg_dst_cmd"
|
||||
|
||||
$pkg_src_cmd = "$Env:USERPROFILE\.local\opt\sql-migrate-v$Env:WEBI_VERSION\bin\sql-migrate.exe"
|
||||
$pkg_src_bin = "$Env:USERPROFILE\.local\opt\sql-migrate-v$Env:WEBI_VERSION\bin"
|
||||
$pkg_src_dir = "$Env:USERPROFILE\.local\opt\sql-migrate-v$Env:WEBI_VERSION"
|
||||
$pkg_src = "$pkg_src_cmd"
|
||||
|
||||
New-Item "$Env:USERPROFILE\Downloads\webi" -ItemType Directory -Force | Out-Null
|
||||
$pkg_download = "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE"
|
||||
|
||||
# Fetch archive
|
||||
if (!(Test-Path -Path "$Env:USERPROFILE\Downloads\webi\$Env:WEBI_PKG_FILE")) {
|
||||
Write-Output "Downloading sql-migrate from $Env:WEBI_PKG_URL to $pkg_download"
|
||||
& curl.exe -A "$Env:WEBI_UA" -fsSL "$Env:WEBI_PKG_URL" -o "$pkg_download.part"
|
||||
& Move-Item "$pkg_download.part" "$pkg_download"
|
||||
}
|
||||
|
||||
if (!(Test-Path -Path "$pkg_src_cmd")) {
|
||||
Write-Output "Installing sql-migrate"
|
||||
|
||||
Push-Location .local\tmp
|
||||
|
||||
Remove-Item -Path ".\sql-migrate-v*" -Recurse -ErrorAction Ignore
|
||||
Remove-Item -Path ".\sql-migrate.exe" -Recurse -ErrorAction Ignore
|
||||
|
||||
Write-Output "Unpacking $pkg_download"
|
||||
& tar xf "$pkg_download"
|
||||
|
||||
Write-Output "Install Location: $pkg_src_cmd"
|
||||
New-Item "$pkg_src_bin" -ItemType Directory -Force | Out-Null
|
||||
Move-Item -Path ".\sql-migrate.exe" -Destination "$pkg_src_bin"
|
||||
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
Write-Output "Copying into '$pkg_dst_cmd' from '$pkg_src_cmd'"
|
||||
Remove-Item -Path "$pkg_dst_cmd" -Recurse -ErrorAction Ignore | Out-Null
|
||||
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
|
||||
33
sql-migrate/install.sh
Normal file
33
sql-migrate/install.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/sh
|
||||
# shellcheck disable=SC2034
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
__init_sql_migrate() {
|
||||
pkg_cmd_name="sql-migrate"
|
||||
|
||||
pkg_dst_cmd="${HOME}/.local/bin/sql-migrate"
|
||||
pkg_dst="${pkg_dst_cmd}"
|
||||
|
||||
pkg_src_cmd="${HOME}/.local/opt/sql-migrate-v${WEBI_VERSION}/bin/sql-migrate"
|
||||
pkg_src_dir="${HOME}/.local/opt/sql-migrate-v${WEBI_VERSION}"
|
||||
pkg_src="${pkg_src_cmd}"
|
||||
|
||||
pkg_install() {
|
||||
pkg_src_bin=$(dirname "${pkg_src_cmd}")
|
||||
mkdir -p "${pkg_src_bin}"
|
||||
mv ./sql-migrate "${pkg_src_cmd}"
|
||||
}
|
||||
|
||||
# pkg_get_current_version is recommended, but (soon) not required
|
||||
pkg_get_current_version() {
|
||||
# 'sql-migrate version' has output in this format:
|
||||
# sql-migrate v0.0.0-dev 0000000 (0001-01-01)
|
||||
# This trims it down to just the version number:
|
||||
# v0.0.0-dev
|
||||
sql-migrate version 2> /dev/null | head -n 1 | cut -d ' ' -f 2
|
||||
}
|
||||
}
|
||||
|
||||
__init_sql_migrate
|
||||
2
sql-migrate/releases.conf
Normal file
2
sql-migrate/releases.conf
Normal file
@@ -0,0 +1,2 @@
|
||||
github_releases = therootcompany/golib
|
||||
tag_prefix = cmd/sql-migrate/v
|
||||
@@ -10,6 +10,7 @@ __rmrf_local() {
|
||||
arc \
|
||||
archiver \
|
||||
awless \
|
||||
basecamp \
|
||||
bat \
|
||||
btop \
|
||||
caddy \
|
||||
@@ -107,6 +108,7 @@ __rmrf_local() {
|
||||
arc \
|
||||
archiver \
|
||||
awless \
|
||||
basecamp \
|
||||
bat \
|
||||
caddy \
|
||||
chromedriver \
|
||||
@@ -206,6 +208,7 @@ __test() {
|
||||
arc \
|
||||
archiver \
|
||||
awless \
|
||||
basecamp \
|
||||
bat \
|
||||
caddy \
|
||||
chromedriver \
|
||||
|
||||
Reference in New Issue
Block a user