Skip to content

Add DROP TABLE and CREATE TABLE (DDL) formatting#13

Merged
kinnell merged 1 commit into
mainfrom
ddl-formatting
Mar 30, 2026
Merged

Add DROP TABLE and CREATE TABLE (DDL) formatting#13
kinnell merged 1 commit into
mainfrom
ddl-formatting

Conversation

@kinnell
Copy link
Copy Markdown
Owner

@kinnell kinnell commented Mar 30, 2026

Description

This PR serves to add formatting support for DROP TABLE and CREATE TABLE DDL statements, and fix single-column INSERT rendering.

Previously, DROP TABLE and CREATE TABLE (with column definitions) statements were not recognized by any parser and fell through to the normalized-text passthrough. They now get proper keyword casing and PascalCase table names, consistent with the rest of the formatter.

The CREATE TABLE parser supports modifiers (TEMP, TEMPORARY, UNLOGGED, LOCAL) and IF NOT EXISTS, preserving column definitions as-is. The modifier constant previously defined in CreateTableAs has been extracted to Constants::TABLE_MODIFIERS so both parsers can share it.

A small fix to InsertQuery#render_column_list ensures single-column lists render inline (e.g., insert into Table (id)) instead of expanding to three lines.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class formatting support for basic DDL statements (DROP TABLE, CREATE TABLE with column definitions) so they no longer fall back to normalized-text passthrough, and fixes single-column INSERT column-list rendering to stay inline.

Changes:

  • Add SqlBeautifier::DropTable and SqlBeautifier::CreateTable parsers/renderers and integrate them into Formatter.
  • Centralize CREATE TABLE modifier keywords in Constants::TABLE_MODIFIERS (shared by CreateTableAs and CreateTable).
  • Fix InsertQuery#render_column_list to render single-column lists inline and expand tests/docs accordingly.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
spec/sql_beautifier/insert_query.spec.rb Adds coverage for inline single-column INSERT column lists and updates existing expectations.
spec/sql_beautifier/formatter.spec.rb Integration coverage for DROP TABLE / CREATE TABLE and single-column INSERT through the main formatter.
spec/sql_beautifier/drop_table.spec.rb New unit specs for DROP TABLE parsing/rendering and configuration interactions.
spec/sql_beautifier/create_table.spec.rb New unit specs for CREATE TABLE (DDL) parsing/rendering and configuration interactions.
spec/sql_beautifier.spec.rb Verifies multi-statement formatting across DROP/CREATE/INSERT sequences.
spec/readme.spec.rb Adds/updates README example expectations, including new DDL examples.
lib/sql_beautifier/insert_query.rb Implements inline rendering for single-column column lists.
lib/sql_beautifier/formatter.rb Routes DROP TABLE and CREATE TABLE statements to their new formatters.
lib/sql_beautifier/drop_table.rb Introduces DROP TABLE parser/renderer.
lib/sql_beautifier/create_table_as.rb Switches modifier detection to shared Constants::TABLE_MODIFIERS.
lib/sql_beautifier/create_table.rb Introduces CREATE TABLE (DDL) parser/renderer for column-definition form.
lib/sql_beautifier/constants.rb Adds TABLE_MODIFIERS shared constant.
lib/sql_beautifier.rb Requires the new DropTable/CreateTable implementations.
README.md Documents new DROP TABLE / CREATE TABLE formatting support with examples.
CHANGELOG.md Records the new DDL formatting support and the INSERT single-column rendering fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/sql_beautifier/drop_table.rb
Comment thread lib/sql_beautifier/create_table.rb
Comment thread lib/sql_beautifier/create_table.rb
@kinnell kinnell merged commit 4afcd22 into main Mar 30, 2026
2 checks passed
@kinnell kinnell deleted the ddl-formatting branch March 30, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants