Skip to content

Commit

Permalink
Merge pull request #156 from liam-hq/add_column_comment_parsing_for_s…
Browse files Browse the repository at this point in the history
…chemarb_parser

Extract column comments for schemarb parser
  • Loading branch information
MH4GF authored Dec 4, 2024
2 parents 8ec000a + 868b8ed commit bced833
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions frontend/packages/db-structure/src/parser/schemarb/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,25 @@ describe(processor, () => {

expect(result).toEqual(expected)
})

it('column commnet', async () => {
const result = await processor(/* Ruby */ `
create_table "users" do |t|
t.string "name", comment: 'this is name'
end
`)

const expected = userTable({
columns: {
name: aColumn({
name: 'name',
type: 'string',
comment: 'this is name',
}),
},
})

expect(result).toEqual(expected)
})
})
})
4 changes: 4 additions & 0 deletions frontend/packages/db-structure/src/parser/schemarb/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ function extractColumnOptions(hashNode: KeywordHashNode, column: Column): void {
case 'unique':
column.unique = value instanceof TrueNode
break
case 'comment':
// @ts-expect-error: unescaped is defined as string but it is actually object
column.comment = value.unescaped.value
break
}
}
}
Expand Down

0 comments on commit bced833

Please sign in to comment.