From 868b8edf2ffcf0a25380ad6384b38579ed2cda21 Mon Sep 17 00:00:00 2001 From: "ryota.sasazawa" Date: Wed, 4 Dec 2024 19:17:10 +0900 Subject: [PATCH] Add support for column comments in schemarb parser --- .../src/parser/schemarb/index.test.ts | 20 +++++++++++++++++++ .../src/parser/schemarb/parser.ts | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/frontend/packages/db-structure/src/parser/schemarb/index.test.ts b/frontend/packages/db-structure/src/parser/schemarb/index.test.ts index 2b9fb1f00..978efc87d 100644 --- a/frontend/packages/db-structure/src/parser/schemarb/index.test.ts +++ b/frontend/packages/db-structure/src/parser/schemarb/index.test.ts @@ -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) + }) }) }) diff --git a/frontend/packages/db-structure/src/parser/schemarb/parser.ts b/frontend/packages/db-structure/src/parser/schemarb/parser.ts index 5b6ec8c36..0a516825f 100644 --- a/frontend/packages/db-structure/src/parser/schemarb/parser.ts +++ b/frontend/packages/db-structure/src/parser/schemarb/parser.ts @@ -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 } } }