Skip to content

Commit 7963abf

Browse files
committed
Add SQL formatting tests for ALTER TABLE and DROP TABLE statements
1 parent e5f4110 commit 7963abf

File tree

9 files changed

+47
-0
lines changed

9 files changed

+47
-0
lines changed

src/test/kotlin/org/domaframework/doma/intellij/formatter/SqlFormatterTest.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@ class SqlFormatterTest : BasePlatformTestCase() {
278278
formatSqlFile("OrderByGroupWithConditionDirective.sql", "OrderByGroupWithConditionDirective$formatDataPrefix.sql")
279279
}
280280

281+
fun testAlterTableAddColumnFormatter() {
282+
formatSqlFile("AlterTableAddColumn.sql", "AlterTableAddColumn$formatDataPrefix.sql")
283+
}
284+
285+
fun testAlterTableAddForeignFormatter() {
286+
formatSqlFile("AlterTableAddForeign.sql", "AlterTableAddForeign$formatDataPrefix.sql")
287+
}
288+
289+
fun testDropTableFormatter() {
290+
formatSqlFile("DropTable.sql", "DropTable$formatDataPrefix.sql")
291+
}
292+
293+
fun testDropTableIfExistsFormatter() {
294+
formatSqlFile("DropTableIfExists.sql", "DropTableIfExists$formatDataPrefix.sql")
295+
}
296+
281297
private fun formatSqlFile(
282298
beforeFile: String,
283299
afterFile: String,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ALTER TABLE /*# tableName */
2+
/*%for column : columns */
3+
ADD COLUMN
4+
IF NOT EXISTS /*# column.name */ /*# column.type */
5+
/*%if column_has_next */
6+
,
7+
/*%end */
8+
/*%end */
9+
DROP COLUMN /*# column2.name */ /*# column2.type */
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ALTER TABLE /*# tableName */
2+
/*%for column : columns */
3+
ADD COLUMN IF NOT EXISTS /*# column.name */ /*# column.type */
4+
/*%if column_has_next */
5+
,
6+
/*%end */
7+
/*%end */
8+
DROP COLUMN /*# column2.name */ /*# column2.type */
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE employee
2+
ADD FOREIGN KEY (employee_id) REFERENCES users(user_iad)
3+
ON
4+
UPDATE RESTRICT
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE employee
2+
ADD FOREIGN KEY (employee_id)
3+
REFERENCES users(user_iad)
4+
ON UPDATE RESTRICT
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Drop TABLE
2+
employees
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DROP TABLE
2+
IF EXISTS employees ;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE IF EXISTS employees ;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE employees

0 commit comments

Comments
 (0)