Skip to content

Commit 7787fd1

Browse files
committed
refactor: update default database path, standardize 'database' casing, and apply minor formatting.
1 parent e634570 commit 7787fd1

File tree

8 files changed

+232
-226
lines changed

8 files changed

+232
-226
lines changed

.agent/rules/naming-conventions.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ Consistent naming across all RiLiGar projects.
44

55
## Quick Reference
66

7-
| Element | Convention | Example |
8-
| --- | --- | --- |
9-
| Components | PascalCase | `UserProfile`, `NavBar` |
10-
| Functions | camelCase | `getUserData`, `handleSubmit` |
11-
| Variables | camelCase | `userName`, `isLoading` |
12-
| Constants | SCREAMING_SNAKE | `API_URL`, `MAX_RETRIES` |
13-
| Files (components) | PascalCase | `UserProfile.jsx` |
14-
| Files (utilities) | camelCase | `formatDate.js` |
15-
| Directories | kebab-case | `user-profile/`, `api-utils/` |
16-
| CSS classes | kebab-case | `nav-bar`, `user-card` |
17-
| Database tables | snake_case | `user_profiles`, `order_items` |
18-
| API endpoints | kebab-case | `/api/user-profiles`, `/api/order-items` |
7+
| Element | Convention | Example |
8+
| ------------------ | --------------- | ---------------------------------------- |
9+
| Components | PascalCase | `UserProfile`, `NavBar` |
10+
| Functions | camelCase | `getUserData`, `handleSubmit` |
11+
| Variables | camelCase | `userName`, `isLoading` |
12+
| Constants | SCREAMING_SNAKE | `API_URL`, `MAX_RETRIES` |
13+
| Files (components) | PascalCase | `UserProfile.jsx` |
14+
| Files (utilities) | camelCase | `formatDate.js` |
15+
| Directories | kebab-case | `user-profile/`, `api-utils/` |
16+
| CSS classes | kebab-case | `nav-bar`, `user-card` |
17+
| database tables | snake_case | `user_profiles`, `order_items` |
18+
| API endpoints | kebab-case | `/api/user-profiles`, `/api/order-items` |
1919

2020
## Components
2121

@@ -59,8 +59,8 @@ const MAX_RETRY_ATTEMPTS = 3
5959
const DEFAULT_PAGE_SIZE = 20
6060

6161
// Bad
62-
const apiBaseUrl = 'https://api.example.com' // camelCase
63-
const maxRetryAttempts = 3 // camelCase
62+
const apiBaseUrl = 'https://api.example.com' // camelCase
63+
const maxRetryAttempts = 3 // camelCase
6464
```
6565

6666
## Booleans
@@ -131,10 +131,10 @@ src/
131131
└── api.js
132132
```
133133

134-
## Database and API
134+
## database and API
135135

136136
```javascript
137-
// Database tables - snake_case
137+
// database tables - snake_case
138138
// user_profiles, order_items, payment_transactions
139139

140140
// API endpoints - kebab-case
@@ -162,7 +162,7 @@ const htmlContent = '<div>...</div>'
162162
const xmlParser = new Parser()
163163

164164
// Bad
165-
const userID = 123 // ID should be Id
165+
const userID = 123 // ID should be Id
166166
const APIURL = '/api' // Should be ApiUrl
167167
const HTMLContent = '<div>...</div>'
168168
```
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
---
22
name: riligar-dev-database
3-
description: Database patterns for RiLiGar using Drizzle ORM + bun:sqlite. Use when setting up database connections, defining schemas, creating migrations, or writing queries. Covers SQLite on Fly.io volumes with the drizzle-kit workflow.
3+
description: database patterns for RiLiGar using Drizzle ORM + bun:sqlite. Use when setting up database connections, defining schemas, creating migrations, or writing queries. Covers SQLite on Fly.io volumes with the drizzle-kit workflow.
44
---
55

6-
# Database — Drizzle + bun:sqlite
6+
# database — Drizzle + bun:sqlite
77

88
> SQLite nativo no Bun. Zero drivers externos. Base de dados no volume do Fly.io (`/app/data`).
99
1010
## Referências
1111

12-
| Arquivo | Quando usar |
13-
| --- | --- |
14-
| [connection.md](references/connection.md) | Setup inicial: instalação, db.js, drizzle.config |
15-
| [schema.md](references/schema.md) | Definir tabelas, tipos de colunas, relações |
16-
| [migrations.md](references/migrations.md) | Criar e executar migrations com drizzle-kit |
17-
| [queries.md](references/queries.md) | Select, insert, update, delete, queries com relações |
12+
| Arquivo | Quando usar |
13+
| ----------------------------------------- | ---------------------------------------------------- |
14+
| [connection.md](references/connection.md) | Setup inicial: instalação, db.js, drizzle.config |
15+
| [schema.md](references/schema.md) | Definir tabelas, tipos de colunas, relações |
16+
| [migrations.md](references/migrations.md) | Criar e executar migrations com drizzle-kit |
17+
| [queries.md](references/queries.md) | Select, insert, update, delete, queries com relações |
1818

1919
## Quick Start
2020

2121
```javascript
2222
// database/db.js
2323
import { drizzle } from 'drizzle-orm/bun-sqlite'
24-
import Database from 'bun:sqlite'
24+
import database from 'bun:sqlite'
2525

26-
const sqlite = new Database(process.env.DB_PATH ?? './data/database.db')
26+
const sqlite = new database(process.env.DB_PATH ?? './database/database.db')
2727
const db = drizzle({ client: sqlite })
2828

2929
export { db }
3030
```
3131
3232
## Regras
3333
34-
- **Caminho do banco:** `/app/data/database.db` em produção (volume Fly.io). `./data/database.db` em desenvolvimento.
34+
- **Caminho do banco:** `/app/data/database.db` em produção (volume Fly.io). `./database/database.db` em desenvolvimento.
3535
- **Migrations sempre:** Use `drizzle-kit generate` + `drizzle-kit migrate`. Nunca edite migrations à mão.
3636
- **Schema único:** Todas as tabelas em `database/schema.js`.
3737
- **Migrations no startup:** Use `migrate()` no `index.js` antes de `.listen()`.
3838
3939
## Related Skills
4040
41-
| Need | Skill |
42-
| --- | --- |
43-
| **Backend (Elysia)** | @[.agent/skills/riligar-dev-manager] |
41+
| Need | Skill |
42+
| --------------------- | ------------------------------------- |
43+
| **Backend (Elysia)** | @[.agent/skills/riligar-dev-manager] |
4444
| **Payments (Stripe)** | @[.agent/skills/riligar-infra-stripe] |
45-
| **Infrastructure** | @[.agent/skills/riligar-infra-fly] |
45+
| **Infrastructure** | @[.agent/skills/riligar-infra-fly] |

.agent/skills/riligar-dev-database/references/connection.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Database Connection
1+
# database Connection
22

33
## Installation
44

@@ -14,15 +14,15 @@ No additional drivers needed — `bun:sqlite` is built into Bun.
1414
```javascript
1515
// database/db.js
1616
import { drizzle } from 'drizzle-orm/bun-sqlite'
17-
import Database from 'bun:sqlite'
17+
import database from 'bun:sqlite'
1818

19-
const sqlite = new Database(process.env.DB_PATH ?? './data/database.db')
19+
const sqlite = new database(process.env.DB_PATH ?? './database/database.db')
2020
const db = drizzle({ client: sqlite })
2121

2222
export { db }
2323
```
2424
25-
- Em **desenvolvimento**: `DB_PATH` não é definido → usa `./data/database.db`
25+
- Em **desenvolvimento**: `DB_PATH` não é definido → usa `./database/database.db`
2626
- Em **produção** (Fly.io): `fly secrets set DB_PATH=/app/data/database.db`
2727
2828
## drizzle.config.js
@@ -36,7 +36,7 @@ export default defineConfig({
3636
schema: './database/schema.js',
3737
out: './database/migrations',
3838
dbCredentials: {
39-
url: process.env.DB_PATH ?? './data/database.db',
39+
url: process.env.DB_PATH ?? './database/database.db',
4040
},
4141
})
4242
```
@@ -53,9 +53,7 @@ import { db } from './database/db'
5353
await migrate(db, { migrationsFolder: './database/migrations' })
5454

5555
// ... resto do setup
56-
const app = new Elysia()
57-
.use(routes)
58-
.listen(3000)
56+
const app = new Elysia().use(routes).listen(3000)
5957
```
6058
6159
Isso garante que o banco esteja sempre atualizado quando o servidor inicia no Fly.io.

.agent/skills/riligar-dev-database/references/queries.md

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ import { eq, and, or, desc, asc } from 'drizzle-orm'
1717
const allUsers = await db.select().from(users)
1818

1919
// Campos específicos
20-
const names = await db.select({
21-
id: users.id,
22-
name: users.name,
23-
}).from(users)
20+
const names = await db
21+
.select({
22+
id: users.id,
23+
name: users.name,
24+
})
25+
.from(users)
2426
```
2527

2628
### Filtrar
@@ -30,23 +32,24 @@ const names = await db.select({
3032
const [user] = await db.select().from(users).where(eq(users.id, userId)).limit(1)
3133

3234
// Múltiplos filtros (AND)
33-
const results = await db.select().from(users).where(
34-
and(
35-
eq(users.active, true),
36-
eq(users.plan, 'pro')
37-
)
38-
)
35+
const results = await db
36+
.select()
37+
.from(users)
38+
.where(and(eq(users.active, true), eq(users.plan, 'pro')))
3939

4040
// OR
41-
const results = await db.select().from(users).where(
42-
or(eq(users.id, '1'), eq(users.id, '2'))
43-
)
41+
const results = await db
42+
.select()
43+
.from(users)
44+
.where(or(eq(users.id, '1'), eq(users.id, '2')))
4445
```
4546

4647
### Ordenar e Paginar
4748

4849
```javascript
49-
const page = await db.select().from(posts)
50+
const page = await db
51+
.select()
52+
.from(posts)
5053
.orderBy(desc(posts.createdAt))
5154
.limit(10)
5255
.offset(pageIndex * 10)
@@ -59,9 +62,7 @@ const page = await db.select().from(posts)
5962
await db.insert(users).values({ name: 'Dan', email: 'dan@email.com' })
6063

6164
// Com retorno
62-
const [user] = await db.insert(users)
63-
.values({ name: 'Dan', email: 'dan@email.com' })
64-
.returning()
65+
const [user] = await db.insert(users).values({ name: 'Dan', email: 'dan@email.com' }).returning()
6566

6667
// Múltiplos
6768
await db.insert(users).values([
@@ -70,7 +71,8 @@ await db.insert(users).values([
7071
])
7172

7273
// Upsert (conflict handling)
73-
await db.insert(users)
74+
await db
75+
.insert(users)
7476
.values({ id: '1', name: 'Dan' })
7577
.onConflictDoUpdate({
7678
target: users.id,
@@ -81,15 +83,10 @@ await db.insert(users)
8183
## Update
8284

8385
```javascript
84-
await db.update(users)
85-
.set({ name: 'Mr. Dan', updatedAt: new Date() })
86-
.where(eq(users.id, userId))
86+
await db.update(users).set({ name: 'Mr. Dan', updatedAt: new Date() }).where(eq(users.id, userId))
8787

8888
// Com retorno
89-
const [updated] = await db.update(users)
90-
.set({ plan: 'pro' })
91-
.where(eq(users.id, userId))
92-
.returning()
89+
const [updated] = await db.update(users).set({ plan: 'pro' }).where(eq(users.id, userId)).returning()
9390
```
9491

9592
## Delete
@@ -98,9 +95,7 @@ const [updated] = await db.update(users)
9895
await db.delete(users).where(eq(users.id, userId))
9996

10097
// Com retorno
101-
const [deleted] = await db.delete(users)
102-
.where(eq(users.id, userId))
103-
.returning()
98+
const [deleted] = await db.delete(users).where(eq(users.id, userId)).returning()
10499
```
105100

106101
## Queries com Relações
@@ -159,7 +154,8 @@ export async function createUser(data) {
159154
}
160155

161156
export async function updateUser(id, data) {
162-
const [user] = await db.update(users)
157+
const [user] = await db
158+
.update(users)
163159
.set({ ...data, updatedAt: new Date() })
164160
.where(eq(users.id, id))
165161
.returning()

.agent/skills/riligar-dev-database/references/schema.md

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,41 @@ import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'
88
import { relations } from 'drizzle-orm'
99

1010
export const users = sqliteTable('users', {
11-
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
11+
id: text('id')
12+
.primaryKey()
13+
.$defaultFn(() => crypto.randomUUID()),
1214
email: text('email').notNull().unique(),
1315
name: text('name'),
14-
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
16+
createdAt: integer('created_at', { mode: 'timestamp' })
17+
.notNull()
18+
.$defaultFn(() => new Date()),
1519
updatedAt: integer('updated_at', { mode: 'timestamp' }),
1620
})
1721
```
1822

1923
## Tipos de Colunas
2024

21-
| Tipo | Uso | Exemplo |
22-
| --- | --- | --- |
23-
| `text()` | Strings, UUIDs, JSON | `text('name').notNull()` |
24-
| `integer()` | Números, booleans, timestamps | `integer('age')` |
25-
| `real()` | Decimais (float) | `real('price')` |
26-
| `blob()` | Dados binários | `blob('avatar')` |
27-
| `numeric()` | Valores numéricos precisos | `numeric('amount')` |
25+
| Tipo | Uso | Exemplo |
26+
| ----------- | ----------------------------- | ------------------------ |
27+
| `text()` | Strings, UUIDs, JSON | `text('name').notNull()` |
28+
| `integer()` | Números, booleans, timestamps | `integer('age')` |
29+
| `real()` | Decimais (float) | `real('price')` |
30+
| `blob()` | Dados binários | `blob('avatar')` |
31+
| `numeric()` | Valores numéricos precisos | `numeric('amount')` |
2832

2933
### Modes do `integer()`
3034

3135
```javascript
32-
integer('count') // número
33-
integer('active', { mode: 'boolean' }) // boolean (0/1)
34-
integer('created_at', { mode: 'timestamp' }) // Date (segundos)
36+
integer('count') // número
37+
integer('active', { mode: 'boolean' }) // boolean (0/1)
38+
integer('created_at', { mode: 'timestamp' }) // Date (segundos)
3539
integer('created_at', { mode: 'timestamp_ms' }) // Date (milissegundos)
3640
```
3741

3842
### JSON via `text()`
3943

4044
```javascript
41-
text('metadata', { mode: 'json' }) // armazena JSON como text
45+
text('metadata', { mode: 'json' }) // armazena JSON como text
4246
```
4347

4448
## Primary Key
@@ -55,11 +59,17 @@ id: integer('id').primaryKey({ autoIncrement: true }),
5559

5660
```javascript
5761
export const posts = sqliteTable('posts', {
58-
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
59-
authorId: text('author_id').notNull().references(() => users.id),
62+
id: text('id')
63+
.primaryKey()
64+
.$defaultFn(() => crypto.randomUUID()),
65+
authorId: text('author_id')
66+
.notNull()
67+
.references(() => users.id),
6068
title: text('title').notNull(),
6169
body: text('body'),
62-
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
70+
createdAt: integer('created_at', { mode: 'timestamp' })
71+
.notNull()
72+
.$defaultFn(() => new Date()),
6373
})
6474
```
6575

@@ -84,8 +94,12 @@ export const postsRelations = relations(posts, ({ one }) => ({
8494

8595
```javascript
8696
export const usersToGroups = sqliteTable('users_to_groups', {
87-
userId: text('user_id').notNull().references(() => users.id),
88-
groupId: text('group_id').notNull().references(() => groups.id),
97+
userId: text('user_id')
98+
.notNull()
99+
.references(() => users.id),
100+
groupId: text('group_id')
101+
.notNull()
102+
.references(() => groups.id),
89103
})
90104

91105
export const usersRelations = relations(users, ({ many }) => ({

0 commit comments

Comments
 (0)