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_Sgh96_DNLHMxXgvWxdKfB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"crates/vespertide/Cargo.toml":"Patch","crates/vespertide-core/Cargo.toml":"Patch","crates/vespertide-planner/Cargo.toml":"Patch","crates/vespertide-cli/Cargo.toml":"Patch","crates/vespertide-query/Cargo.toml":"Patch","crates/vespertide-exporter/Cargo.toml":"Patch","crates/vespertide-macro/Cargo.toml":"Patch","crates/vespertide-config/Cargo.toml":"Patch"},"note":"Refactor column type","date":"2025-12-14T13:29:18.853713900Z"}
16 changes: 8 additions & 8 deletions Cargo.lock

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

88 changes: 51 additions & 37 deletions SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,34 @@ Models are JSON files in the `models/` directory:

| Type | PostgreSQL | Use Cases |
|------|------------|-----------|
| `"Integer"` | INTEGER | IDs, counters |
| `"BigInt"` | BIGINT | Large numbers |
| `"Text"` | TEXT | Strings |
| `"Boolean"` | BOOLEAN | Flags |
| `"Timestamp"` | TIMESTAMP | Date/time |
| `"small_int"` | SMALLINT | Small integers (-32768 to 32767) |
| `"integer"` | INTEGER | IDs, counters |
| `"big_int"` | BIGINT | Large numbers |
| `"real"` | REAL | Single precision float |
| `"double_precision"` | DOUBLE PRECISION | Double precision float |
| `"text"` | TEXT | Strings |
| `"boolean"` | BOOLEAN | Flags |
| `"date"` | DATE | Date only |
| `"time"` | TIME | Time only |
| `"timestamp"` | TIMESTAMP | Date/time without timezone |
| `"timestamptz"` | TIMESTAMPTZ | Date/time with timezone |
| `"bytea"` | BYTEA | Binary data |
| `"uuid"` | UUID | UUIDs |
| `"json"` | JSON | JSON data |
| `"jsonb"` | JSONB | Binary JSON (indexable) |
| `"inet"` | INET | IPv4/IPv6 address |
| `"cidr"` | CIDR | Network address |
| `"macaddr"` | MACADDR | MAC address |

### Custom Types

For types not covered above:

```json
{ "Custom": "UUID" }
{ "Custom": "JSONB" }
{ "Custom": "DECIMAL(10,2)" }
{ "Custom": "VARCHAR(255)" }
{ "Custom": "TIMESTAMPTZ" }
{ "custom": "DECIMAL(10,2)" }
{ "custom": "VARCHAR(255)" }
{ "custom": "NUMERIC(20,8)" }
{ "custom": "INTERVAL" }
```

## Inline Constraints
Expand All @@ -100,7 +114,7 @@ Models are JSON files in the `models/` directory:
```json
{
"name": "id",
"type": "Integer",
"type": "integer",
"nullable": false,
"primary_key": true
}
Expand All @@ -109,33 +123,33 @@ Models are JSON files in the `models/` directory:
### Unique

```json
{ "name": "email", "type": "Text", "nullable": false, "unique": true }
{ "name": "email", "type": "text", "nullable": false, "unique": true }
```

Named or composite unique:
```json
{ "name": "tenant_id", "type": "Integer", "nullable": false, "unique": ["uq_tenant_user"] },
{ "name": "username", "type": "Text", "nullable": false, "unique": ["uq_tenant_user"] }
{ "name": "tenant_id", "type": "integer", "nullable": false, "unique": ["uq_tenant_user"] },
{ "name": "username", "type": "text", "nullable": false, "unique": ["uq_tenant_user"] }
```

### Index

```json
{ "name": "email", "type": "Text", "nullable": false, "index": true }
{ "name": "email", "type": "text", "nullable": false, "index": true }
```

Composite index:
```json
{ "name": "user_id", "type": "Integer", "nullable": false, "index": ["idx_user_date"] },
{ "name": "created_at", "type": "Timestamp", "nullable": false, "index": ["idx_user_date"] }
{ "name": "user_id", "type": "integer", "nullable": false, "index": ["idx_user_date"] },
{ "name": "created_at", "type": "timestamp", "nullable": false, "index": ["idx_user_date"] }
```

### Foreign Key

```json
{
"name": "user_id",
"type": "Integer",
"type": "integer",
"nullable": false,
"foreign_key": {
"ref_table": "user",
Expand Down Expand Up @@ -178,10 +192,10 @@ Reference actions: `"Cascade"`, `"Restrict"`, `"SetNull"`, `"SetDefault"`, `"NoA
"$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json",
"name": "user",
"columns": [
{ "name": "id", "type": "Integer", "nullable": false, "primary_key": true },
{ "name": "email", "type": "Text", "nullable": false, "unique": true, "index": true },
{ "name": "name", "type": "Text", "nullable": false },
{ "name": "created_at", "type": "Timestamp", "nullable": false, "default": "NOW()" }
{ "name": "id", "type": "integer", "nullable": false, "primary_key": true },
{ "name": "email", "type": "text", "nullable": false, "unique": true, "index": true },
{ "name": "name", "type": "text", "nullable": false },
{ "name": "created_at", "type": "timestamptz", "nullable": false, "default": "NOW()" }
],
"constraints": [],
"indexes": []
Expand All @@ -195,12 +209,12 @@ Reference actions: `"Cascade"`, `"Restrict"`, `"SetNull"`, `"SetDefault"`, `"NoA
"$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json",
"name": "post",
"columns": [
{ "name": "id", "type": "Integer", "nullable": false, "primary_key": true },
{ "name": "user_id", "type": "Integer", "nullable": false, "foreign_key": { "ref_table": "user", "ref_columns": ["id"], "on_delete": "Cascade" }, "index": true },
{ "name": "title", "type": "Text", "nullable": false },
{ "name": "content", "type": "Text", "nullable": false },
{ "name": "published", "type": "Boolean", "nullable": false, "default": "false" },
{ "name": "created_at", "type": "Timestamp", "nullable": false, "default": "NOW()" }
{ "name": "id", "type": "integer", "nullable": false, "primary_key": true },
{ "name": "user_id", "type": "integer", "nullable": false, "foreign_key": { "ref_table": "user", "ref_columns": ["id"], "on_delete": "Cascade" }, "index": true },
{ "name": "title", "type": "text", "nullable": false },
{ "name": "content", "type": "text", "nullable": false },
{ "name": "published", "type": "boolean", "nullable": false, "default": "false" },
{ "name": "created_at", "type": "timestamptz", "nullable": false, "default": "NOW()" }
],
"constraints": [],
"indexes": []
Expand All @@ -214,12 +228,12 @@ Reference actions: `"Cascade"`, `"Restrict"`, `"SetNull"`, `"SetDefault"`, `"NoA
"$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json",
"name": "order",
"columns": [
{ "name": "id", "type": { "Custom": "UUID" }, "nullable": false, "primary_key": true, "default": "gen_random_uuid()" },
{ "name": "customer_id", "type": "Integer", "nullable": false, "foreign_key": { "ref_table": "customer", "ref_columns": ["id"], "on_delete": "Restrict" }, "index": true },
{ "name": "total_amount", "type": { "Custom": "DECIMAL(10,2)" }, "nullable": false },
{ "name": "status", "type": "Text", "nullable": false, "default": "'pending'" },
{ "name": "metadata", "type": { "Custom": "JSONB" }, "nullable": true },
{ "name": "created_at", "type": "Timestamp", "nullable": false, "default": "NOW()" }
{ "name": "id", "type": "uuid", "nullable": false, "primary_key": true, "default": "gen_random_uuid()" },
{ "name": "customer_id", "type": "integer", "nullable": false, "foreign_key": { "ref_table": "customer", "ref_columns": ["id"], "on_delete": "Restrict" }, "index": true },
{ "name": "total_amount", "type": { "custom": "DECIMAL(10,2)" }, "nullable": false },
{ "name": "status", "type": "text", "nullable": false, "default": "'pending'" },
{ "name": "metadata", "type": "jsonb", "nullable": true },
{ "name": "created_at", "type": "timestamptz", "nullable": false, "default": "NOW()" }
],
"constraints": [
{ "type": "check", "name": "check_total_positive", "expr": "total_amount >= 0" }
Expand All @@ -235,9 +249,9 @@ Reference actions: `"Cascade"`, `"Restrict"`, `"SetNull"`, `"SetDefault"`, `"NoA
"$schema": "https://raw.githubusercontent.com/dev-five-git/vespertide/refs/heads/main/schemas/model.schema.json",
"name": "user_role",
"columns": [
{ "name": "user_id", "type": "Integer", "nullable": false, "primary_key": true, "foreign_key": { "ref_table": "user", "ref_columns": ["id"], "on_delete": "Cascade" } },
{ "name": "role_id", "type": "Integer", "nullable": false, "primary_key": true, "foreign_key": { "ref_table": "role", "ref_columns": ["id"], "on_delete": "Cascade" } },
{ "name": "assigned_at", "type": "Timestamp", "nullable": false, "default": "NOW()" }
{ "name": "user_id", "type": "integer", "nullable": false, "primary_key": true, "foreign_key": { "ref_table": "user", "ref_columns": ["id"], "on_delete": "Cascade" } },
{ "name": "role_id", "type": "integer", "nullable": false, "primary_key": true, "foreign_key": { "ref_table": "role", "ref_columns": ["id"], "on_delete": "Cascade" } },
{ "name": "assigned_at", "type": "timestamptz", "nullable": false, "default": "NOW()" }
],
"constraints": [],
"indexes": [
Expand Down
8 changes: 4 additions & 4 deletions crates/vespertide-cli/src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ mod tests {
use std::path::PathBuf;
use tempfile::tempdir;
use vespertide_config::VespertideConfig;
use vespertide_core::{ColumnDef, ColumnType, TableDef};
use vespertide_core::{ColumnDef, ColumnType, SimpleColumnType, TableDef};

struct CwdGuard {
original: PathBuf,
Expand Down Expand Up @@ -221,7 +221,7 @@ mod tests {
name: name.to_string(),
columns: vec![ColumnDef {
name: "id".into(),
r#type: ColumnType::Integer,
r#type: ColumnType::Simple(SimpleColumnType::Integer),
nullable: false,
default: None,
comment: None,
Expand Down Expand Up @@ -251,7 +251,7 @@ mod tests {
table: "users".into(),
column: ColumnDef {
name: "name".into(),
r#type: ColumnType::Text,
r#type: ColumnType::Simple(SimpleColumnType::Text),
nullable: true,
default: None,
comment: None,
Expand Down Expand Up @@ -280,7 +280,7 @@ mod tests {
MigrationAction::ModifyColumnType {
table: "users".into(),
column: "id".into(),
new_type: ColumnType::Integer,
new_type: ColumnType::Simple(SimpleColumnType::Integer),
},
format!("{} {}.{}", "Modify column type:".bright_yellow(), "users".bright_cyan(), "id".bright_cyan().bold())
)]
Expand Down
4 changes: 2 additions & 2 deletions crates/vespertide-cli/src/commands/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod tests {
use serial_test::serial;
use std::fs;
use tempfile::tempdir;
use vespertide_core::{ColumnDef, ColumnType, TableConstraint};
use vespertide_core::{ColumnDef, ColumnType, SimpleColumnType, TableConstraint};

struct CwdGuard {
original: PathBuf,
Expand Down Expand Up @@ -194,7 +194,7 @@ mod tests {
name: name.to_string(),
columns: vec![ColumnDef {
name: "id".into(),
r#type: ColumnType::Integer,
r#type: ColumnType::Simple(SimpleColumnType::Integer),
nullable: false,
default: None,
comment: None,
Expand Down
4 changes: 2 additions & 2 deletions crates/vespertide-cli/src/commands/revision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ mod tests {
use std::{env, fs, path::PathBuf};
use tempfile::tempdir;
use vespertide_config::{FileFormat, VespertideConfig};
use vespertide_core::{ColumnDef, ColumnType, TableDef};
use vespertide_core::{ColumnDef, ColumnType, SimpleColumnType, TableDef};

struct CwdGuard {
original: PathBuf,
Expand Down Expand Up @@ -165,7 +165,7 @@ mod tests {
name: name.to_string(),
columns: vec![ColumnDef {
name: "id".into(),
r#type: ColumnType::Integer,
r#type: ColumnType::Simple(SimpleColumnType::Integer),
nullable: false,
default: None,
comment: None,
Expand Down
7 changes: 4 additions & 3 deletions crates/vespertide-cli/src/commands/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ mod tests {
use tempfile::tempdir;
use vespertide_config::VespertideConfig;
use vespertide_core::{
ColumnDef, ColumnType, MigrationAction, MigrationPlan, TableConstraint, TableDef,
ColumnDef, ColumnType, MigrationAction, MigrationPlan, SimpleColumnType, TableConstraint,
TableDef,
};

struct CwdGuard {
Expand Down Expand Up @@ -114,7 +115,7 @@ mod tests {
name: name.to_string(),
columns: vec![ColumnDef {
name: "id".into(),
r#type: ColumnType::Integer,
r#type: ColumnType::Simple(SimpleColumnType::Integer),
nullable: false,
default: None,
comment: None,
Expand Down Expand Up @@ -165,7 +166,7 @@ mod tests {
table: "users".into(),
columns: vec![ColumnDef {
name: "id".into(),
r#type: ColumnType::Integer,
r#type: ColumnType::Simple(SimpleColumnType::Integer),
nullable: false,
default: None,
comment: None,
Expand Down
8 changes: 5 additions & 3 deletions crates/vespertide-cli/src/commands/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ mod tests {
use std::{fs, path::PathBuf};
use tempfile::tempdir;
use vespertide_config::VespertideConfig;
use vespertide_core::{ColumnDef, ColumnType, MigrationAction, MigrationPlan, TableDef};
use vespertide_core::{
ColumnDef, ColumnType, MigrationAction, MigrationPlan, SimpleColumnType, TableDef,
};

struct CwdGuard {
original: PathBuf,
Expand Down Expand Up @@ -177,7 +179,7 @@ mod tests {
name: name.to_string(),
columns: vec![ColumnDef {
name: "id".into(),
r#type: ColumnType::Integer,
r#type: ColumnType::Simple(SimpleColumnType::Integer),
nullable: false,
default: None,
comment: None,
Expand All @@ -203,7 +205,7 @@ mod tests {
table: "users".into(),
columns: vec![ColumnDef {
name: "id".into(),
r#type: ColumnType::Integer,
r#type: ColumnType::Simple(SimpleColumnType::Integer),
nullable: false,
default: None,
comment: None,
Expand Down
Loading