Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add DBStructure schema #83

Merged
merged 5 commits into from
Nov 14, 2024
Merged
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
50 changes: 49 additions & 1 deletion frontend/packages/db-structure/src/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,57 @@
import * as v from 'valibot'

const tablesSchema = v.object({})
const fieldNameSchema = v.string()

const tableNameSchema = v.string()

const relationshipNameSchema = v.string()

const fieldSchema = v.object({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

name: fieldNameSchema,
type: v.string(),
default: v.string(),
check: v.string(),
primary: v.boolean(),
unique: v.boolean(),
notNull: v.boolean(),
increment: v.boolean(),
comment: v.string(),
})

const indexSchema = v.object({
name: v.string(),
unique: v.boolean(),
fields: v.array(v.string()),
})

const tableSchema = v.object({
name: tableNameSchema,
x: v.number(),
y: v.number(),
fields: v.array(fieldSchema),
comment: v.string(),
indices: v.array(indexSchema),
color: v.string(),
})

const relationshipSchema = v.object({
name: relationshipNameSchema,
startTableName: tableNameSchema,
startFieldName: fieldNameSchema,
endTableName: tableNameSchema,
endFieldName: fieldNameSchema,
cardinality: v.string(),
updateConstraint: v.string(),
deleteConstraint: v.string(),
})

const tablesSchema = v.record(tableNameSchema, tableSchema)

const relationshipsSchema = v.record(relationshipNameSchema, relationshipSchema)

export const dbStructureSchema = v.object({
tables: tablesSchema,
relationships: relationshipsSchema,
})

export type DBStructure = v.InferOutput<typeof dbStructureSchema>