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
1 change: 1 addition & 0 deletions .changepacks/changepack_log_KYO7bQOcPhhU8kIwATtUP.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"crates/vespertide-config/Cargo.toml":"Patch","crates/vespertide-exporter/Cargo.toml":"Patch","crates/vespertide-naming/Cargo.toml":"Patch","crates/vespertide-loader/Cargo.toml":"Patch","crates/vespertide/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch","crates/vespertide-cli/Cargo.toml":"Patch","crates/vespertide-macro/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide-core/Cargo.toml":"Patch"},"note":"Fix auto increament issue on sqlite","date":"2026-01-15T12:38:07.170780700Z"}
20 changes: 10 additions & 10 deletions Cargo.lock

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

23 changes: 23 additions & 0 deletions SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ cargo install vespertide-cli

---

## Exported ORM Files (DO NOT EDIT)

> **CRITICAL**: Files generated by `vespertide export` are AUTO-GENERATED. Never modify them manually.

### Rules

1. **Never manually edit** exported files (SeaORM entities, SQLAlchemy models, etc.)
2. **Always regenerate** by running `vespertide export --orm <orm_name>`
3. **Edit source models** in `models/*.json` instead, then re-export

### Workflow

```bash
# 1. Edit your model files (models/*.json)
# 2. Regenerate ORM code
vespertide export --orm seaorm

# 3. Never touch the generated files after this
```

---

## Migration Files (DO NOT EDIT)

> **CRITICAL**: Migration files are AUTO-GENERATED. Never create or modify them manually.
Expand Down Expand Up @@ -625,6 +647,7 @@ Both columns with `"primary_key": true` creates a **single composite primary key
3. **Never add NOT NULL columns without default** - Requires `fill_with` in migration
4. **Never use table-level constraints** - Except for CHECK expressions only
5. **Never manually create/edit migration files** - Only `fill_with` exception
6. **Never manually edit exported ORM files** - Use `vespertide export` to regenerate

### Naming Conventions

Expand Down
12 changes: 11 additions & 1 deletion crates/vespertide-query/src/sql/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ pub(crate) fn build_create_table_for_backend(

// Apply auto_increment if this column is in the auto_increment primary key
if auto_increment_columns.contains(column.name.as_str()) {
// For SQLite, AUTOINCREMENT requires inline PRIMARY KEY (INTEGER PRIMARY KEY AUTOINCREMENT)
// So we must call primary_key() on the column even if there's a table-level PRIMARY KEY
if matches!(backend, DatabaseBackend::Sqlite) {
col.primary_key();
}
col.auto_increment();
}

Expand All @@ -64,8 +69,13 @@ pub(crate) fn build_create_table_for_backend(
match constraint {
TableConstraint::PrimaryKey {
columns: pk_cols,
auto_increment: _,
auto_increment,
} => {
// For SQLite with auto_increment, skip table-level PRIMARY KEY
// because AUTOINCREMENT requires inline PRIMARY KEY on the column
if matches!(backend, DatabaseBackend::Sqlite) && *auto_increment {
continue;
}
// Build primary key index
let mut pk_idx = Index::create();
for c in pk_cols {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: crates/vespertide-query/src/sql/create_table.rs
expression: sql
---
CREATE TABLE "users" ( "id" integer NOT NULL AUTOINCREMENT, PRIMARY KEY ("id") )
CREATE TABLE "users" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT )
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source: crates/vespertide-query/src/sql/create_table.rs
expression: sql
---
CREATE TABLE "users" ( "id" integer NOT NULL AUTOINCREMENT, PRIMARY KEY ("id") )
CREATE TABLE "users" ( "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT )