Skip to content

Commit 8c9fa38

Browse files
authored
feat: implement hybrid timestamp/sequence based migration versioning (#128)
Adds hybrid versioning for migrations: timestamps in development (no conflicts), sequential in production (deterministic ordering). Includes an automated `sqlspec fix` command to convert between formats. Closes #116
1 parent bed7303 commit 8c9fa38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+9307
-298
lines changed

AGENTS.md

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# AGENS.md
1+
# AGENTS.md
22

33
This file provides guidance to Gemini, Claude Code, Codex, and other agents when working with code in this repository.
44

@@ -11,6 +11,96 @@ This file provides guidance to Gemini, Claude Code, Codex, and other agents when
1111
- **Propose improvements**: Suggest better patterns, more robust solutions, or cleaner implementations when appropriate
1212
- **Be a thoughtful collaborator**: Act as a good teammate who helps improve the overall quality and direction of the project
1313

14+
## Pull Request Guidelines
15+
16+
### PR Description Standards (MANDATORY)
17+
18+
Pull request descriptions MUST be concise, factual, and human-readable. Avoid excessive detail that should live in documentation or commit messages.
19+
20+
**Maximum length**: ~30-40 lines for typical features
21+
**Tone**: Direct, clear, professional - no marketing language or excessive enthusiasm
22+
23+
**Required sections**:
24+
25+
1. **Summary** (2-3 sentences): What does this do and why?
26+
2. **The Problem** (2-4 lines): What issue does this solve?
27+
3. **The Solution** (2-4 lines): How does it solve it?
28+
4. **Key Features** (3-5 bullet points): Most important capabilities
29+
5. **Example** (optional): Brief code example if it clarifies usage
30+
6. **Link to docs** (if comprehensive guide exists)
31+
32+
**PROHIBITED content**:
33+
34+
- Extensive test coverage tables (this belongs in CI reports)
35+
- Detailed file change lists (GitHub shows this automatically)
36+
- Quality metrics and linting results (CI handles this)
37+
- Commit-by-commit breakdown (git history shows this)
38+
- Implementation details (belongs in code comments/docs)
39+
- Excessive formatting (tables, sections, subsections)
40+
- Marketing language or hype
41+
42+
**Example of GOOD PR description**:
43+
44+
```markdown
45+
## Summary
46+
47+
Adds hybrid versioning for migrations: timestamps in development (no conflicts),
48+
sequential in production (deterministic ordering). Includes an automated
49+
`sqlspec fix` command to convert between formats.
50+
51+
Closes #116
52+
53+
## The Problem
54+
55+
- Sequential migrations (0001, 0002): merge conflicts when multiple devs create migrations
56+
- Timestamp migrations (20251011120000): no conflicts, but ordering depends on creation time
57+
58+
## The Solution
59+
60+
Use timestamps during development, convert to sequential before merging:
61+
62+
$ sqlspec create-migration -m "add users"
63+
Created: 20251011120000_add_users.sql
64+
65+
$ sqlspec fix --yes
66+
✓ Converted to 0003_add_users.sql
67+
68+
## Key Features
69+
70+
- Automated conversion via `sqlspec fix` command
71+
- Updates database tracking to prevent errors
72+
- Idempotent - safe to re-run after pulling changes
73+
- Stable checksums through conversions
74+
75+
See [docs/guides/migrations/hybrid-versioning.md](docs/guides/migrations/hybrid-versioning.md)
76+
for full documentation.
77+
```
78+
79+
**Example of BAD PR description**:
80+
81+
```markdown
82+
## Summary
83+
[800+ lines of excessive detail including test counts, file changes,
84+
quality metrics, implementation details, commit lists, etc.]
85+
```
86+
87+
**CI Integration examples** - Keep to 5-10 lines maximum:
88+
89+
```yaml
90+
# GitHub Actions example
91+
- run: sqlspec fix --yes
92+
- run: git add migrations/ && git commit && git push
93+
```
94+
95+
**When to include more detail**:
96+
97+
- Breaking changes warrant a "Breaking Changes" section
98+
- Complex architectural changes may need a "Design Decisions" section
99+
- Security fixes may need a "Security Impact" section
100+
101+
Keep it focused: the PR description should help reviewers understand WHAT and WHY quickly.
102+
Implementation details belong in code, commits, and documentation.
103+
14104
## Common Development Commands
15105
16106
### Building and Installation
@@ -53,7 +143,7 @@ SQLSpec is a type-safe SQL query mapper designed for minimal abstraction between
53143
2. **Adapters (`sqlspec/adapters/`)**: Database-specific implementations. Each adapter consists of:
54144
- `config.py`: Configuration classes specific to the database
55145
- `driver.py`: Driver implementation (sync/async) that executes queries
56-
- `_types.py`: Type definitions specific to the adapter or other uncompilable mypyc onbjects
146+
- `_types.py`: Type definitions specific to the adapter or other uncompilable mypyc objects
57147
- Supported adapters: `adbc`, `aiosqlite`, `asyncmy`, `asyncpg`, `bigquery`, `duckdb`, `oracledb`, `psqlpy`, `psycopg`, `sqlite`
58148

59149
3. **Driver System (`sqlspec/driver/`)**: Base classes and mixins for all database drivers:

docs/changelog.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,58 @@ SQLSpec Changelog
1010
Recent Updates
1111
==============
1212

13+
Hybrid Versioning with Fix Command
14+
-----------------------------------
15+
16+
Added comprehensive hybrid versioning support for database migrations:
17+
18+
- **Fix Command** - Convert timestamp migrations to sequential format
19+
- **Hybrid Workflow** - Use timestamps in development, sequential in production
20+
- **Automatic Conversion** - CI integration for seamless workflow
21+
- **Safety Features** - Automatic backup, rollback on errors, dry-run preview
22+
23+
Key Features:
24+
25+
- **Zero merge conflicts**: Developers use timestamps (``20251011120000``) during development
26+
- **Deterministic ordering**: Production uses sequential format (``0001``, ``0002``, etc.)
27+
- **Database synchronization**: Automatically updates version tracking table
28+
- **File operations**: Renames files and updates SQL query names
29+
- **CI-ready**: ``--yes`` flag for automated workflows
30+
31+
.. code-block:: bash
32+
33+
# Preview changes
34+
sqlspec --config myapp.config fix --dry-run
35+
36+
# Apply conversion
37+
sqlspec --config myapp.config fix
38+
39+
# CI/CD mode
40+
sqlspec --config myapp.config fix --yes --no-database
41+
42+
Example conversion:
43+
44+
.. code-block:: text
45+
46+
Before: After:
47+
migrations/ migrations/
48+
├── 0001_initial.sql ├── 0001_initial.sql
49+
├── 0002_add_users.sql ├── 0002_add_users.sql
50+
├── 20251011120000_products.sql → ├── 0003_add_products.sql
51+
└── 20251012130000_orders.sql → └── 0004_add_orders.sql
52+
53+
**Documentation:**
54+
55+
- Complete CLI reference: :doc:`usage/cli`
56+
- Workflow guide: :ref:`hybrid-versioning-guide`
57+
- CI integration examples for GitHub Actions and GitLab CI
58+
59+
**Use Cases:**
60+
61+
- Teams with parallel development avoiding migration number conflicts
62+
- Projects requiring deterministic migration ordering in production
63+
- CI/CD pipelines that standardize migrations before deployment
64+
1365
Shell Completion Support
1466
-------------------------
1567

docs/conf.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
"sphinx_paramlinks",
6363
"sphinxcontrib.mermaid",
6464
]
65-
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "guides/*"]
6665
intersphinx_mapping = {
6766
"python": ("https://docs.python.org/3", None),
6867
"msgspec": ("https://jcristharif.com/msgspec/", None),
@@ -156,7 +155,15 @@
156155
templates_path = ["_templates"]
157156
html_js_files = ["versioning.js"]
158157
html_css_files = ["custom.css"]
159-
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "PYPI_README.md", "STYLE_GUIDE.md", "VOICE_AUDIT_REPORT.md"]
158+
exclude_patterns = [
159+
"_build",
160+
"Thumbs.db",
161+
".DS_Store",
162+
"PYPI_README.md",
163+
"STYLE_GUIDE.md",
164+
"VOICE_AUDIT_REPORT.md",
165+
"guides/**",
166+
]
160167
html_show_sourcelink = True
161168
html_copy_source = True
162169

docs/extensions/adk/migrations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ SQLSpec includes a built-in migration for ADK tables:
148148
149149
from sqlspec.extensions.adk.migrations import create_adk_tables_migration
150150
151-
Location: ``sqlspec/extensions/adk/migrations/0001_create_adk_tables.py``
151+
Location: ``sqlspec/extensions/adk/migrations/``
152152

153153
You can copy this template for custom migrations:
154154

docs/guides/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ Optimization guides for SQLSpec:
2828
- [**SQLglot Guide**](performance/sqlglot.md) - SQL parsing, transformation, and optimization with SQLglot
2929
- [**MyPyC Guide**](performance/mypyc.md) - Compilation strategies for high-performance Python code
3030

31+
## Migrations
32+
33+
Database migration strategies and workflows:
34+
35+
- [**Hybrid Versioning**](migrations/hybrid-versioning.md) - Combine timestamp and sequential versioning for optimal workflows
36+
3137
## Testing
3238

3339
Testing strategies and patterns:
@@ -91,6 +97,8 @@ docs/guides/
9197
│ ├── oracle.md
9298
│ ├── postgres.md
9399
│ └── ...
100+
├── migrations/ # Migration workflows
101+
│ └── hybrid-versioning.md
94102
├── performance/ # Performance optimization
95103
│ ├── sqlglot.md
96104
│ └── mypyc.md

0 commit comments

Comments
 (0)