From 50870636bf3d12a9d838a45d05ebf04416279799 Mon Sep 17 00:00:00 2001
From: Kijin-Seija <almon123@qq.com>
Date: Tue, 28 May 2024 18:17:07 +0800
Subject: [PATCH 1/2] fix: add alter table stmt

---
 package.json                                  |  3 ++-
 src/parser/common/entityCollector.ts          |  1 +
 .../postgresql/postgreEntityCollector.ts      |  7 +++++++
 .../fixtures/suggestionWithEntity.sql         |  4 +++-
 .../suggestion/suggestionWithEntity.test.ts   | 21 +++++++++++++++++++
 5 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/package.json b/package.json
index 9c07879d..d150f4bc 100644
--- a/package.json
+++ b/package.json
@@ -29,7 +29,8 @@
     "lint": "prettier --check '**/*.ts' --config ./.prettierrc",
     "lint-fix": "prettier --write '**/*.ts' --config ./.prettierrc",
     "format-g4": "antlr-format -c ./antlr.format.json -v ./src/grammar/**/*.g4",
-    "cleanComment": "node ./scripts/cleanCommentCli.js"
+    "cleanComment": "node ./scripts/cleanCommentCli.js",
+    "test-kijin-temp": "NODE_OPTIONS=--max_old_space_size=4096 && jest test/parser/postgresql/suggestion/suggestionWithEntity.test.ts"
   },
   "license": "MIT",
   "devDependencies": {
diff --git a/src/parser/common/entityCollector.ts b/src/parser/common/entityCollector.ts
index 60bbbf97..a7579bcc 100644
--- a/src/parser/common/entityCollector.ts
+++ b/src/parser/common/entityCollector.ts
@@ -17,6 +17,7 @@ export enum StmtContextType {
     SELECT_STMT = 'selectStmt',
     INSERT_STMT = 'insertStmt',
     CREATE_FUNCTION_STMT = 'createFunctionStmt',
+    ALTER_TABLE_STMT = 'alterTableStmt',
 }
 
 export interface StmtContext {
diff --git a/src/parser/postgresql/postgreEntityCollector.ts b/src/parser/postgresql/postgreEntityCollector.ts
index 47eaf237..8bf5308e 100644
--- a/src/parser/postgresql/postgreEntityCollector.ts
+++ b/src/parser/postgresql/postgreEntityCollector.ts
@@ -1,4 +1,5 @@
 import type {
+    AltertablestmtContext,
     ColumnCreateTableContext,
     ColumnNameCreateContext,
     CreateDatabaseContext,
@@ -145,4 +146,10 @@ export class PostgreSqlEntityCollector extends EntityCollector implements Postgr
     exitCreatefunctionstmt(ctx: CreatefunctionstmtContext) {
         this.popStmt();
     }
+    enterAltertablestmt(ctx: AltertablestmtContext) {
+        this.pushStmt(ctx, StmtContextType.ALTER_TABLE_STMT);
+    }
+    exitAltertablestmt(ctx: AltertablestmtContext) {
+        this.popStmt();
+    }
 }
diff --git a/test/parser/postgresql/suggestion/fixtures/suggestionWithEntity.sql b/test/parser/postgresql/suggestion/fixtures/suggestionWithEntity.sql
index 6bbbf123..8824296e 100644
--- a/test/parser/postgresql/suggestion/fixtures/suggestionWithEntity.sql
+++ b/test/parser/postgresql/suggestion/fixtures/suggestionWithEntity.sql
@@ -8,4 +8,6 @@ INSERT INTO insert_tb SELECT id, age,  FROM from_tb;
 
 CREATE TABLE sorted_census_data AS SELECT  FROM unsorted_census_data;
 
-CREATE TABLE sorted_census_data AS SELECT id, age,  FROM unsorted_census_data;
\ No newline at end of file
+CREATE TABLE sorted_census_data AS SELECT id, age,  FROM unsorted_census_data;
+
+ALTER TABLE my_table DROP a_column;
\ No newline at end of file
diff --git a/test/parser/postgresql/suggestion/suggestionWithEntity.test.ts b/test/parser/postgresql/suggestion/suggestionWithEntity.test.ts
index f89bc016..ab840ba6 100644
--- a/test/parser/postgresql/suggestion/suggestionWithEntity.test.ts
+++ b/test/parser/postgresql/suggestion/suggestionWithEntity.test.ts
@@ -153,4 +153,25 @@ describe('PostgreSql Syntax Suggestion with collect entity', () => {
         expect(entities[1].entityContextType).toBe(EntityContextType.TABLE);
         expect(entities[1].belongStmt.isContainCaret).toBeTruthy();
     });
+
+    test('alter table drop column', () => {
+        const pos: CaretPosition = {
+            lineNumber: 13,
+            column: 35,
+        };
+        const sql = commentOtherLine(syntaxSql, pos.lineNumber);
+
+        const syntaxes = postgre.getSuggestionAtCaretPosition(sql, pos)?.syntax;
+        const suggestion = syntaxes?.find(
+            (syn) => syn.syntaxContextType === EntityContextType.COLUMN
+        );
+        expect(suggestion).not.toBeUndefined();
+        expect(suggestion?.wordRanges.map((token) => token.text)).toEqual(['a_column']);
+
+        const entities = postgre.getAllEntities(sql, pos);
+        expect(entities.length).toBe(1);
+        expect(entities[0].text).toBe('my_table');
+        expect(entities[0].entityContextType).toBe(EntityContextType.TABLE);
+        expect(entities[0].belongStmt?.isContainCaret).toBeTruthy();
+    });
 });

From e33eb9f85a1f48f7a58f16adb603408fb6b3d99f Mon Sep 17 00:00:00 2001
From: Kijin-Seija <almon123@qq.com>
Date: Wed, 5 Jun 2024 15:52:52 +0800
Subject: [PATCH 2/2] fix: delete personal unused scripts

---
 package.json | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/package.json b/package.json
index d150f4bc..9c07879d 100644
--- a/package.json
+++ b/package.json
@@ -29,8 +29,7 @@
     "lint": "prettier --check '**/*.ts' --config ./.prettierrc",
     "lint-fix": "prettier --write '**/*.ts' --config ./.prettierrc",
     "format-g4": "antlr-format -c ./antlr.format.json -v ./src/grammar/**/*.g4",
-    "cleanComment": "node ./scripts/cleanCommentCli.js",
-    "test-kijin-temp": "NODE_OPTIONS=--max_old_space_size=4096 && jest test/parser/postgresql/suggestion/suggestionWithEntity.test.ts"
+    "cleanComment": "node ./scripts/cleanCommentCli.js"
   },
   "license": "MIT",
   "devDependencies": {