Skip to content

Commit

Permalink
feat: Add promote command (#22)
Browse files Browse the repository at this point in the history
### **User description**
To convert wip templates to buildable migration templates


___

### **PR Type**
Enhancement


___

### **Description**
- Added a new `promote` command to convert WIP templates to buildable
migration templates.

- Implemented a new `Promote` component with CLI and interactive UI
modes.

- Updated the command menu to include the new `promote` command.

- Added a changeset file to document the new feature.


___



### **Changes walkthrough** 📝
<table><thead><tr><th></th><th align="left">Relevant
files</th></tr></thead><tbody><tr><td><strong>Enhancement</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>index.tsx</strong><dd><code>Integrate `promote` command
into command menu</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

src/commands/index.tsx

<li>Added the <code>Promote</code> component to the command menu.<br>
<li> Included a new menu item for the <code>promote</code> command.<br>
<li> Adjusted the <code>Select</code> component to show more options.


</details>


  </td>
<td><a
href="https://github.com/t1mmen/srtd/pull/22/files#diff-28dd48060efda88c3ae7ffc80ff0a3fa13de4c93e5d0042cedbd658cfa448a9a">+7/-1</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>

<tr>
  <td>
    <details>
<summary><strong>promote.tsx</strong><dd><code>Implement `Promote`
component for WIP template promotion</code>&nbsp; </dd></summary>
<hr>

src/commands/promote.tsx

<li>Created a new <code>Promote</code> component for promoting WIP
templates.<br> <li> Added CLI and interactive UI modes for template
promotion.<br> <li> Implemented error handling and success feedback for
the promotion <br>process.<br> <li> Utilized configuration and build log
utilities for template <br>management.


</details>


  </td>
<td><a
href="https://github.com/t1mmen/srtd/pull/22/files#diff-75e818a1d9e0c0a59e5bfea012f2d5ce88370ebc77f1e99bfa09e0c6b1765091">+195/-0</a>&nbsp;
</td>

</tr>
</table></td></tr><tr><td><strong>Documentation</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>quiet-birds-play.md</strong><dd><code>Document
`promote` command in changeset</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; </dd></summary>
<hr>

.changeset/quiet-birds-play.md

- Added a changeset file documenting the new `promote` command.


</details>


  </td>
<td><a
href="https://github.com/t1mmen/srtd/pull/22/files#diff-9b4fb4eb7c2ebca995564182672c8cf29cbcbe6f4672ae5d011087dd93ec73c8">+5/-0</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>
</table></td></tr><tr><td><strong>Dependencies</strong></td><td><table>
<tr>
  <td>
    <details>
<summary><strong>package-lock.json</strong><dd><code>Update package
version to 0.4.4</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
</dd></summary>
<hr>

package-lock.json

- Updated the package version from 0.4.3 to 0.4.4.


</details>


  </td>
<td><a
href="https://github.com/t1mmen/srtd/pull/22/files#diff-053150b640a7ce75eff69d1a22cae7f0f94ad64ce9a855db544dda0929316519">+2/-2</a>&nbsp;
&nbsp; &nbsp; </td>

</tr>
</table></td></tr></tr></tbody></table>

___

> 💡 **PR-Agent usage**: Comment `/help "your question"` on any pull
request to receive relevant information
  • Loading branch information
t1mmen authored Jan 5, 2025
1 parent 719cd95 commit 8391b2b
Show file tree
Hide file tree
Showing 18 changed files with 581 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-birds-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@t1mmen/srtd": patch
---

Add command for promoting .wip templates to buildable migration templates
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ build
logs
*.log
npm-debug.log*

.DS_Store
*.tsbuildinfo
.npm
.env

# srtd's local logs should not be committed, as they're per-environment specific
.srtd.buildlog.local.json

62 changes: 45 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

> Live-reloading SQL templates for [Supabase](https://supabase.com) projects. DX supercharged! 🚀
![NPM Version](https://img.shields.io/npm/v/%40t1mmen%2Fsrtd)
[![NPM Version](https://img.shields.io/npm/v/%40t1mmen%2Fsrtd)](https://www.npmjs.com/package/@t1mmen/srtd)
[![Downloads](https://img.shields.io/npm/dt/%40t1mmen%2Fsrtd)](https://www.npmjs.com/package/@t1mmen/srtd)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![CI/CD](https://github.com/t1mmen/srtd/actions/workflows/ci.yml/badge.svg)](https://github.com/t1mmen/srtd/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/t1mmen/srtd/graph/badge.svg?token=CIMAZ55KCJ)](https://codecov.io/gh/t1mmen/srtd)


[![screenshot of srtd](./readme-screenshot.png)](./readme-screenshot.png)
[![video demo](./readme-demo.gif)](./readme-demo.gif)


`srtd` enhances the [Supabase](https://supabase.com) DX by adding live-reloading SQL templates into local db. The single-source-of-truth template ➡️ migrations system brings sanity to code reviews, making `git blame` useful.

Expand All @@ -28,6 +30,8 @@ I spent [nearly two years looking](https://news.ycombinator.com/item?id=37755076

Say hello to `srtd`.

[![screenshot of srtd](./readme-screenshot.png)](./readme-screenshot.png)

## Key Features ✨

- **Live Reload**: Changes to your SQL templates instantly update your local database
Expand Down Expand Up @@ -62,7 +66,7 @@ npx @t1mmen/srtd

```bash
cd your-supabase-project
srtd init
npx @t1mmen/srtd init # Creates srtd.config.json, not required
```

### Create Your First Template
Expand All @@ -82,16 +86,20 @@ $$ LANGUAGE plpgsql;

1. Start watch mode:
```bash
srtd watch # Changes auto-apply to local database
npx @t1mmen/srtd watch # Changes auto-apply to local database
```

2. When ready to deploy:
```bash
srtd build # Creates timestamped migration file
supabase migration up # Apply using Supabase CLI
npx @t1mmen/srtd build # Creates timestamped migration file
supabase migration up # Apply using Supabase CLI
```


> [!INFO]
> To reduce noise in PR's, consider adding `migration-templates/*srtd*.sql linguist-generated=true` to your [`.gitattributes` file.](https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github) (unless you manually edit the generated files)

## The Power of Templates 💪

Without templates, the smallest change to a function would show up as a complete rewrite in your version control system. With templates, the diff is clear and concise.
Expand Down Expand Up @@ -183,13 +191,12 @@ Use regular [Supabase](https://supabase.com) migrations for these cases.

### Interactive Mode

Running `srtd` without arguments opens an interactive menu:

### CLI Mode
Running `npx @t1mmen/srtd` without arguments opens an interactive menu:

- 🏗️ `srtd build [--force]` - Generate migrations from templates
- ▶️ `srtd apply [--force]` - Apply templates directly to local database
- ✍️ `srtd register [file.sql]` - Mark templates as already built
- ✍️ `srtd register [file.sql...]` - Mark templates as already built
- 🚀 `srtd promote - [file.sql ...]` - Promote WIP template to buildable templates
- 👀 `srtd watch` - Watch and auto-apply changes
- 🧹 `srtd clean` - Remove all logs and reset config

Expand Down Expand Up @@ -238,6 +245,11 @@ Add `.wip.sql` extension to prevent migration generation:
my_function.wip.sql # Only applied locally, never built
```

Make a WIP templates buildable my renaming it, or using the `promote` command:
```bash
npx @t1mmen/srtd promote my_function.wip.sql
```

### Template State Management

Two state tracking files:
Expand All @@ -246,13 +258,14 @@ Two state tracking files:

### Register Existing Objects

Import existing database objects:
Registering a template is useful when you're creating templates for what is already in your database. This avoids generating migrations on `build` (until they're changed)

```bash
# Register specific template
srtd register my_function.sql
npx @t1mmen/srtd register my_function.sql another_fn.sql

# Interactive multi-select UI
srtd register
npx @t1mmen/srtd register
```

## Development 🛠️
Expand All @@ -266,13 +279,15 @@ cd srtd
npm install

# Development
npm run dev # Watch mode
npm test # Run tests
npm start # Build, link, run
npm run dev # Watch mode
npm test # Run tests
npm start # Run CLI
npm start:link # Build, npm link, and run CLI

# Quality Checks
npm run typecheck # Type checking
npm run typecheck # Type checking
npm run lint # Lint and fix
npm run format # Format code
npm run test:coverage # Test coverage
```

Expand All @@ -294,6 +309,19 @@ While feature-complete for our needs, we welcome:

Note: New features are evaluated based on alignment with project scope.

## Built With 🛠️

### Terminal UI
- [Ink](https://github.com/vadimdemedes/ink) - React for CLI interfaces
- [Pastel](https://github.com/vadimdemedes/pastel) - Next-like framework for Ink
- [Figures](https://github.com/sindresorhus/figures) - Unicode symbols
- [Chokidar](https://github.com/paulmillr/chokidar) - File watcher
- [update-notifier](https://github.com/sindresorhus/update-notifier) - Version checks
- [Zod](https://zod.dev/) - Schema validation
- [Conf](https://github.com/sindresorhus/conf) - Config management
- [vhs](https://github.com/charmbracelet/vhs) - Video recording


## License

MIT License - see [LICENSE](LICENSE) file.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
"test": "vitest",
"test:coverage": "vitest run --coverage --reporter=junit --outputFile=test-report.junit.xml",
"start": "tsx src/cli.tsx",
"start:link": "npm run build && npm link && chmod u+x ./dist/cli.js && srtd",
"repomix": "mkdir build; npx repomix",
"supabase:start": "npx supabase start",
"supabase:stop": "npx supabase stop"
"supabase:stop": "npx supabase stop",
"vhs": "chmod +x scripts/record_demo.sh && ./scripts/record_demo.sh"
},
"files": [
"dist"
Expand Down
Binary file added readme-demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 121 additions & 0 deletions readme-demo.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# See https://github.com/charmbracelet/vhs
# Generate with `npm run vhs`

Output readme-demo.gif

Require npx

# Setup the terminal
Set FontSize 16
Set Width 1024
Set Height 550
Set TypingSpeed 10ms
Set Theme "Catppuccin Mocha"
Set WindowBar Colorful

# Initialize SRTD
# Type "clear" Enter
Type "srtd init"
Enter
Sleep 1s
Hide
Sleep 2s
Ctrl+C
Show
Sleep 250ms

# Create our first templates
Type "echo '-- SQL for hello..' >> supabase/migrations-templates/hello.sql"
Enter
Sleep 50ms
Type "echo '-- More fake SQL..' >> supabase/migrations-templates/test.sql"
Enter
Sleep 50ms
Type "echo '-- Another one...' >> supabase/migrations-templates/another_test.sql"
Enter
Sleep 50ms
Type "echo '-- WIP SQL here..' >> supabase/migrations-templates/experiment.wip.sql"
Enter
Sleep 50ms
Enter

# Apply changes directly
Type "srtd apply" Enter
Hide
Sleep 2
Show
Sleep 2s
Hide
Sleep 1s
Ctrl+C
Show

# More templates
Type "echo '-- Changes to existing template' >> supabase/migrations-templates/hello.sql" Enter
Sleep 50ms
Type "echo '-- New template' >> supabase/migrations-templates/new.sql" Enter
Sleep 1s

# Start watching for changes
Type "srtd watch"
Sleep 1s
Enter
Hide
Sleep 1s
Show
Sleep 5s
Hide
Ctrl+C
Enter
Show
Sleep 1s

# Build migration files
Type "srtd build"
Sleep 100ms
Enter
Hide
Sleep 2
Enter
Show
Sleep 3s

# Make a change to hello.sql
Type "echo '-- Another update to hello' >> supabase/migrations-templates/hello.sql" Enter
Enter
Sleep 1s

# Build migration files
Type "srtd build" Enter
Sleep 3s
Hide
Ctrl+C
Show

# Promote the WIP template
Type "srtd promote experiment.wip.sql"
Enter
Hide
Sleep 1s
Show
Sleep 2s

# Build migration files
Type "srtd build" Enter
Sleep 3s
Hide
Ctrl+C
Show

# Show the resulting files
Type "ls -1p supabase/migrations/"
Enter
Hide
Enter
Show
Sleep 1s

# Success message
Enter
Type "✨ Thanks for watching! Check out github.com/t1mmen/srtd for more info"
Sleep 5s
Binary file modified readme-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions readme-screenshot.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Screenshots for README.md documentation
Output readme-screenshots.gif

Require npx

# Terminal setup
Set FontSize 16
Set Width 840
Set Height 480
Set BorderRadius 4
Set TypingSpeed 20ms
Set Theme "Catppuccin Mocha"

# Default command
Type "clear" Enter
Sleep 200ms
Type "npx @t1mmen/srtd@latest" Enter
Sleep 5s
Screenshot readme-screenshot-default.png
Sleep 1s
Ctrl+C

# Watch command
Type "clear" Enter
Sleep 200ms
Type "npx @t1mmen/srtd@latest watch" Enter
Sleep 5s
Screenshot readme-screenshot-watch.png
Hide
Ctrl+C
Show
Sleep 1s

# Register command
Type "clear" Enter
Sleep 200ms
Type "npx @t1mmen/srtd@latest register" Enter
Sleep 5s
Screenshot readme-screenshot-register.png
Sleep 1s
Ctrl+C

# Promote command
Type "clear" Enter
Sleep 200ms
Type "npx @t1mmen/srtd@latest promote" Enter
Sleep 5s
Screenshot readme-screenshot-promote.png
Sleep 1s
Ctrl+C

# Clean command
Type "clear" Enter
Sleep 200ms
Type "npx @t1mmen/srtd@latest clean" Enter
Sleep 5s
Screenshot readme-screenshot-clean.png
Sleep 1s
Ctrl+C
Loading

0 comments on commit 8391b2b

Please sign in to comment.