Skip to content

Commit

Permalink
Merge pull request #125 from liam-hq/fix-default-value
Browse files Browse the repository at this point in the history
fix: support multiple default values in schema
  • Loading branch information
hoshinotsuyoshi authored Dec 2, 2024
2 parents 72b3c7e + 813d0b2 commit 27e9085
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
5 changes: 0 additions & 5 deletions frontend/packages/cli/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ function App() {
result.success
? setSchemaJsonContent(result.output)
: console.info(result.issues)

// This is a temporary workaround.
// For demo purposes, we ignore the validation result and set the schema content directly.
// TODO: remove this line.
setSchemaJsonContent(data)
} catch (error) {
console.error('Error loading schema content:', error)
}
Expand Down
13 changes: 12 additions & 1 deletion frontend/packages/db-structure/src/parser/schemarb/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ describe(processor, () => {
const result = processor(/* Ruby */ `
create_table "users" do |t|
t.string "name", default: "new user", null: true
t.bigint "age", default: 0, null: true
t.boolean "is_admin", default: false, null: true
end
`)

Expand All @@ -73,9 +75,18 @@ describe(processor, () => {
name: aColumn({
name: 'name',
type: 'string',
notNull: false,
default: 'new user',
}),
age: aColumn({
name: 'age',
type: 'bigint',
default: 0,
}),
is_admin: aColumn({
name: 'is_admin',
type: 'boolean',
default: false,
}),
},
})

Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/db-structure/src/schema/dbStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const relationshipNameSchema = v.string()
const columnSchema = v.object({
name: columnNameSchema,
type: v.string(),
default: v.nullable(v.string()),
default: v.nullable(v.union([v.string(), v.number(), v.boolean()])),
check: v.nullable(v.string()),
primary: v.boolean(),
unique: v.boolean(),
Expand Down

0 comments on commit 27e9085

Please sign in to comment.