Initial commit
This commit is contained in:
28
skills/database-conventions/templates/drizzle-table.ts
Normal file
28
skills/database-conventions/templates/drizzle-table.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
// Grey Haven Studio - Drizzle Table Template
|
||||
// Copy this template for new database tables
|
||||
|
||||
import { pgTable, uuid, text, timestamp, boolean, index } from "drizzle-orm/pg-core";
|
||||
|
||||
// TODO: Update table name
|
||||
export const resources = pgTable("resources", {
|
||||
// Primary key
|
||||
id: uuid("id").primaryKey().defaultRandom(),
|
||||
|
||||
// Timestamps (REQUIRED on all tables)
|
||||
created_at: timestamp("created_at").defaultNow().notNull(),
|
||||
updated_at: timestamp("updated_at").defaultNow().notNull().$onUpdate(() => new Date()),
|
||||
|
||||
// Multi-tenant (REQUIRED on all tables)
|
||||
tenant_id: uuid("tenant_id").notNull(),
|
||||
|
||||
// TODO: Add your fields here (use snake_case!)
|
||||
name: text("name").notNull(),
|
||||
description: text("description"),
|
||||
is_active: boolean("is_active").default(true).notNull(),
|
||||
|
||||
// Soft delete (optional but recommended)
|
||||
deleted_at: timestamp("deleted_at"),
|
||||
});
|
||||
|
||||
// Indexes (REQUIRED for tenant_id)
|
||||
export const resourcesIndex = index("resources_tenant_id_idx").on(resources.tenant_id);
|
||||
36
skills/database-conventions/templates/sqlmodel-table.py
Normal file
36
skills/database-conventions/templates/sqlmodel-table.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# Grey Haven Studio - SQLModel Table Template
|
||||
# Copy this template for new database tables
|
||||
|
||||
from sqlmodel import Field, SQLModel
|
||||
from uuid import UUID, uuid4
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
# Reusable timestamp mixin
|
||||
class TimestampMixin:
|
||||
"""Mixin for created_at and updated_at timestamps."""
|
||||
created_at: datetime = Field(default_factory=datetime.utcnow)
|
||||
updated_at: datetime = Field(
|
||||
default_factory=datetime.utcnow,
|
||||
sa_column_kwargs={"onupdate": datetime.utcnow}
|
||||
)
|
||||
|
||||
# TODO: Update class and table name
|
||||
class Resource(TimestampMixin, SQLModel, table=True):
|
||||
"""Resource model with multi-tenant isolation."""
|
||||
|
||||
__tablename__ = "resources"
|
||||
|
||||
# Primary key
|
||||
id: UUID = Field(default_factory=uuid4, primary_key=True)
|
||||
|
||||
# Multi-tenant (REQUIRED on all tables)
|
||||
tenant_id: UUID = Field(foreign_key="tenants.id", index=True)
|
||||
|
||||
# TODO: Add your fields here (use snake_case!)
|
||||
name: str = Field(max_length=255)
|
||||
description: Optional[str] = None
|
||||
is_active: bool = Field(default=True)
|
||||
|
||||
# Soft delete (optional but recommended)
|
||||
deleted_at: Optional[datetime] = None
|
||||
Reference in New Issue
Block a user