Skip to content

Commit 0de30cc

Browse files
Version Packages (#132)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 7b9230c commit 0de30cc

File tree

4 files changed

+100
-88
lines changed

4 files changed

+100
-88
lines changed

.changeset/foreign-key-constraint-merging.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

.changeset/toposort-user-facing.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/cli/CHANGELOG.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,104 @@
11
# @izumisy/kyrage
22

3+
## 1.5.0
4+
5+
### Minor Changes
6+
7+
- [#131](https://github.com/IzumiSy/kyrage/pull/131) [`23e21eb`](https://github.com/IzumiSy/kyrage/commit/23e21ebb259d895b7546383ba9e2c2a6e480e23c) Thanks [@IzumiSy](https://github.com/IzumiSy)! - Add foreign key constraint merging to table creation operations with inline control option
8+
9+
Kyrage now automatically merges foreign key constraints into `CREATE TABLE` statements alongside existing primary key and unique constraints. This reduces SQL operations and improves migration performance. Added `inline` option to schema builder's `reference()` method for fine-grained control over constraint merging.
10+
11+
**Example schema with inline foreign key:**
12+
13+
```typescript
14+
import { column as c, defineTable as t } from "@izumisy/kyrage";
15+
16+
const users = t("users", {
17+
id: c("uuid", { primaryKey: true }),
18+
});
19+
20+
const posts = t(
21+
"posts",
22+
{
23+
id: c("uuid", { primaryKey: true }),
24+
userId: c("uuid"),
25+
},
26+
(t) => [
27+
// Merged into CREATE TABLE (default: inline: true)
28+
t.reference("userId", users, "id"),
29+
]
30+
);
31+
```
32+
33+
**Example with separate constraint:**
34+
35+
```typescript
36+
const posts = t(
37+
"posts",
38+
{
39+
id: c("uuid", { primaryKey: true }),
40+
userId: c("uuid"),
41+
},
42+
(t) => [
43+
// Separate ALTER TABLE statement
44+
t.reference("userId", users, "id", { inline: false }),
45+
]
46+
);
47+
```
48+
49+
### Patch Changes
50+
51+
- [#131](https://github.com/IzumiSy/kyrage/pull/131) [`23e21eb`](https://github.com/IzumiSy/kyrage/commit/23e21ebb259d895b7546383ba9e2c2a6e480e23c) Thanks [@IzumiSy](https://github.com/IzumiSy)! - Table operations are now sorted to always respect foreign key and other dependency relationships. Independent tables are ordered alphabetically, ensuring stable and predictable output for migrations and SQL generation.
52+
53+
**Example:**
54+
55+
```typescript
56+
import { column as c, defineTable as t } from "@izumisy/kyrage";
57+
58+
const users = t("users", {
59+
id: c("uuid", { primaryKey: true }),
60+
name: c("varchar"),
61+
});
62+
63+
const posts = t(
64+
"posts",
65+
{
66+
id: c("uuid", { primaryKey: true }),
67+
userId: c("uuid"),
68+
content: c("text"),
69+
},
70+
(t) => [
71+
t.reference("userId", users, "id"), // posts depends on users
72+
]
73+
);
74+
75+
const categories = t("categories", {
76+
id: c("uuid", { primaryKey: true }),
77+
label: c("varchar"),
78+
});
79+
```
80+
81+
The generated SQL will always be:
82+
83+
```sql
84+
CREATE TABLE categories (
85+
id uuid PRIMARY KEY,
86+
label varchar
87+
);
88+
89+
CREATE TABLE users (
90+
id uuid PRIMARY KEY,
91+
name varchar
92+
);
93+
94+
CREATE TABLE posts (
95+
id uuid PRIMARY KEY,
96+
userId uuid,
97+
content text,
98+
CONSTRAINT posts_userId_fkey FOREIGN KEY (userId) REFERENCES users(id)
99+
);
100+
```
101+
3102
## 1.4.0
4103

5104
### Minor Changes

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@izumisy/kyrage",
33
"private": false,
44
"type": "module",
5-
"version": "1.4.0",
5+
"version": "1.5.0",
66
"description": "A minimal, schema-based declarative migration tool for Node.js ecosystem",
77
"author": "Seiya Izumi (https://github.com/IzumiSy)",
88
"license": "MIT",

0 commit comments

Comments
 (0)