feat: rename properties to projects
- Rename all DB tables: properties → projects, properties_addresses → projects_addresses, properties_models → projects_models, property_likes → projects_likes - Add projects_likes as proper Drizzle schema table (was SQL-only before) - Rename ID prefixes: property_xxx → project_xxx - Rename auth_sessions column: active_property_id → active_project_id - Simplify project creation: address is now optional (no longer required to get started) - Update all actions, stores, types, components, and routes - Rename route: /editor/[propertyId] → /editor/[projectId] - Add SQL migration for table/column/index/policy/function renames - Update RPC functions: increment_project_views, get_project_like_count - Update storage bucket reference: project-thumbnails - All types/exports follow existing Drizzle patterns (pgTable, relations, zod schemas)
This commit is contained in:
@@ -13,8 +13,8 @@ export const sessions = pgTable('auth_sessions', (t) => ({
|
||||
token: t.text('token').notNull(),
|
||||
ipAddress: t.text('ip_address'),
|
||||
userAgent: t.text('user_agent'),
|
||||
// Custom: active property for the session context
|
||||
activePropertyId: t.text('active_property_id'),
|
||||
// Custom: active project for the session context
|
||||
activeProjectId: t.text('active_project_id'),
|
||||
// Admin plugin support: tracks who is impersonating this session
|
||||
impersonatedBy: t
|
||||
.text('impersonated_by')
|
||||
|
||||
@@ -5,7 +5,8 @@ export * from './auth/sessions'
|
||||
export * from './auth/users'
|
||||
export * from './auth/verifications'
|
||||
|
||||
// Property tables
|
||||
export * from './properties/addresses'
|
||||
export * from './properties/models'
|
||||
export * from './properties/properties'
|
||||
// Project tables
|
||||
export * from './projects/addresses'
|
||||
export * from './projects/likes'
|
||||
export * from './projects/models'
|
||||
export * from './projects/projects'
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ import { z } from 'zod'
|
||||
import { id, timestampsColumns } from '../../helpers'
|
||||
|
||||
export const addresses = pgTable(
|
||||
'properties_addresses',
|
||||
'projects_addresses',
|
||||
(t) => ({
|
||||
id: id('address'),
|
||||
streetNumber: t.text('street_number'),
|
||||
@@ -0,0 +1,36 @@
|
||||
import { relations } from 'drizzle-orm'
|
||||
import { pgTable, unique } from 'drizzle-orm/pg-core'
|
||||
import { createInsertSchema, createSelectSchema } from 'drizzle-zod'
|
||||
import { id, createdAt } from '../../helpers'
|
||||
import { projects } from './projects'
|
||||
import { users } from '../auth/users'
|
||||
|
||||
export const projectsLikes = pgTable(
|
||||
'projects_likes',
|
||||
(t) => ({
|
||||
id: id('like'),
|
||||
projectId: t
|
||||
.text('project_id')
|
||||
.notNull()
|
||||
.references(() => projects.id, { onDelete: 'cascade' }),
|
||||
userId: t
|
||||
.text('user_id')
|
||||
.notNull(),
|
||||
createdAt,
|
||||
}),
|
||||
(t) => [
|
||||
unique('projects_likes_project_user_unique').on(t.projectId, t.userId),
|
||||
],
|
||||
).enableRLS()
|
||||
|
||||
export const projectsLikesRelations = relations(projectsLikes, ({ one }) => ({
|
||||
project: one(projects, {
|
||||
fields: [projectsLikes.projectId],
|
||||
references: [projects.id],
|
||||
}),
|
||||
}))
|
||||
|
||||
export type ProjectLike = typeof projectsLikes.$inferSelect
|
||||
export type NewProjectLike = typeof projectsLikes.$inferInsert
|
||||
export const insertProjectLikeSchema = createInsertSchema(projectsLikes)
|
||||
export const selectProjectLikeSchema = createSelectSchema(projectsLikes)
|
||||
+8
-8
@@ -2,26 +2,26 @@ import { relations } from 'drizzle-orm'
|
||||
import { pgTable } from 'drizzle-orm/pg-core'
|
||||
import { createInsertSchema, createSelectSchema } from 'drizzle-zod'
|
||||
import { id, timestampsColumnsSoftDelete } from '../../helpers'
|
||||
import { properties } from './properties'
|
||||
import { projects } from './projects'
|
||||
|
||||
export const models = pgTable('properties_models', (t) => ({
|
||||
export const models = pgTable('projects_models', (t) => ({
|
||||
id: id('model'),
|
||||
name: t.text('name'),
|
||||
version: t.integer('version').default(1),
|
||||
description: t.text('description'),
|
||||
draft: t.boolean('draft').default(true),
|
||||
propertyId: t
|
||||
.text('property_id')
|
||||
.references(() => properties.id, { onDelete: 'set null' }),
|
||||
projectId: t
|
||||
.text('project_id')
|
||||
.references(() => projects.id, { onDelete: 'set null' }),
|
||||
sceneGraph: t.jsonb('scene_graph'),
|
||||
metadata: t.jsonb('metadata'),
|
||||
...timestampsColumnsSoftDelete,
|
||||
})).enableRLS()
|
||||
|
||||
export const modelsRelations = relations(models, ({ one }) => ({
|
||||
property: one(properties, {
|
||||
fields: [models.propertyId],
|
||||
references: [properties.id],
|
||||
project: one(projects, {
|
||||
fields: [models.projectId],
|
||||
references: [projects.id],
|
||||
}),
|
||||
}))
|
||||
|
||||
+16
-17
@@ -5,15 +5,14 @@ import { id, timestampsColumns } from '../../helpers'
|
||||
import { users } from '../auth/users'
|
||||
import { addresses } from './addresses'
|
||||
|
||||
export const properties = pgTable(
|
||||
'properties',
|
||||
export const projects = pgTable(
|
||||
'projects',
|
||||
(t) => ({
|
||||
id: id('property'),
|
||||
id: id('project'),
|
||||
name: t.text('name'),
|
||||
addressId: t
|
||||
.text('address_id')
|
||||
.references(() => addresses.id, { onDelete: 'set null' })
|
||||
.unique(),
|
||||
.references(() => addresses.id, { onDelete: 'set null' }),
|
||||
ownerId: t
|
||||
.text('owner_id')
|
||||
.references(() => users.id, { onDelete: 'set null' }),
|
||||
@@ -27,26 +26,26 @@ export const properties = pgTable(
|
||||
...timestampsColumns,
|
||||
}),
|
||||
(t) => [
|
||||
index('property_address_idx').on(t.addressId),
|
||||
index('property_owner_idx').on(t.ownerId),
|
||||
index('property_is_private_idx').on(t.isPrivate),
|
||||
index('property_views_idx').on(t.views),
|
||||
index('property_likes_idx').on(t.likes),
|
||||
index('project_address_idx').on(t.addressId),
|
||||
index('project_owner_idx').on(t.ownerId),
|
||||
index('project_is_private_idx').on(t.isPrivate),
|
||||
index('project_views_idx').on(t.views),
|
||||
index('project_likes_idx').on(t.likes),
|
||||
],
|
||||
).enableRLS()
|
||||
|
||||
export const propertiesRelations = relations(properties, ({ one }) => ({
|
||||
export const projectsRelations = relations(projects, ({ one }) => ({
|
||||
address: one(addresses, {
|
||||
fields: [properties.addressId],
|
||||
fields: [projects.addressId],
|
||||
references: [addresses.id],
|
||||
}),
|
||||
owner: one(users, {
|
||||
fields: [properties.ownerId],
|
||||
fields: [projects.ownerId],
|
||||
references: [users.id],
|
||||
}),
|
||||
}))
|
||||
|
||||
export type Property = typeof properties.$inferSelect
|
||||
export type NewProperty = typeof properties.$inferInsert
|
||||
export const insertPropertySchema = createInsertSchema(properties)
|
||||
export const selectPropertySchema = createSelectSchema(properties)
|
||||
export type Project = typeof projects.$inferSelect
|
||||
export type NewProject = typeof projects.$inferInsert
|
||||
export const insertProjectSchema = createInsertSchema(projects)
|
||||
export const selectProjectSchema = createSelectSchema(projects)
|
||||
@@ -8,7 +8,7 @@ export type Json = string | number | boolean | null | { [key: string]: Json | un
|
||||
export interface Database {
|
||||
public: {
|
||||
Tables: {
|
||||
properties: {
|
||||
projects: {
|
||||
Row: {
|
||||
id: string
|
||||
name: string
|
||||
@@ -31,10 +31,10 @@ export interface Database {
|
||||
updated_at?: string
|
||||
}
|
||||
}
|
||||
properties_addresses: {
|
||||
projects_addresses: {
|
||||
Row: {
|
||||
id: string
|
||||
property_id: string
|
||||
project_id: string
|
||||
formatted_address: string
|
||||
street_number: string | null
|
||||
route: string | null
|
||||
@@ -51,7 +51,7 @@ export interface Database {
|
||||
}
|
||||
Insert: {
|
||||
id?: string
|
||||
property_id: string
|
||||
project_id: string
|
||||
formatted_address: string
|
||||
street_number?: string | null
|
||||
route?: string | null
|
||||
@@ -68,7 +68,7 @@ export interface Database {
|
||||
}
|
||||
Update: {
|
||||
id?: string
|
||||
property_id?: string
|
||||
project_id?: string
|
||||
formatted_address?: string
|
||||
street_number?: string | null
|
||||
route?: string | null
|
||||
@@ -84,10 +84,10 @@ export interface Database {
|
||||
updated_at?: string
|
||||
}
|
||||
}
|
||||
properties_models: {
|
||||
projects_models: {
|
||||
Row: {
|
||||
id: string
|
||||
property_id: string
|
||||
project_id: string
|
||||
name: string
|
||||
version: number
|
||||
draft: boolean
|
||||
@@ -97,7 +97,7 @@ export interface Database {
|
||||
}
|
||||
Insert: {
|
||||
id?: string
|
||||
property_id: string
|
||||
project_id: string
|
||||
name: string
|
||||
version?: number
|
||||
draft?: boolean
|
||||
@@ -107,7 +107,7 @@ export interface Database {
|
||||
}
|
||||
Update: {
|
||||
id?: string
|
||||
property_id?: string
|
||||
project_id?: string
|
||||
name?: string
|
||||
version?: number
|
||||
draft?: boolean
|
||||
|
||||
Reference in New Issue
Block a user