xnuinside / simple-ddl-parser

Simple DDL Parser to parse SQL (HQL, TSQL, AWS Redshift, BigQuery, Snowflake and other dialects) ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc. & table properties, types, domains, etc.
MIT License
179 stars 40 forks source link

Support for DDL ALTER statement #215

Closed rmorais01 closed 8 months ago

rmorais01 commented 8 months ago

Is your feature request related to a problem? Please describe. A very useful addition to the simple-ddl-parser would be the ability to parse and process the SQL ALTER command for ADD/DROP/RENAME column, MODIFY DATATYPE and MODIFY CONSTRAINT. Currently there is a very limited support for only processing ALTER statements with FOREIGN key.

Describe the solution you'd like The solution must be able to parse the SQL ALTER command and apply the alterations to the Table created using the CREATE command in the same file.

Describe alternatives you've considered NA

Additional context Here are some examples for the ALTER command

ALTER TABLE - ADD Column ALTER TABLE table_name ADD column_name datatype;

ALTER TABLE - DROP COLUMN ALTER TABLE table_name DROP COLUMN column_name;

ALTER TABLE - RENAME COLUMN ALTER TABLE table_name RENAME COLUMN old_name to new_name;

ALTER TABLE - ALTER/MODIFY DATATYPE ALTER TABLE table_name ALTER COLUMN column_name datatype; (SQL Server) ALTER TABLE table_name MODIFY COLUMN column_name datatype; (My SQL / Oracle (prior version 10G) ALTER TABLE table_name MODIFY column_name datatype; (Oracle 10G and later:)

abhishek0102 commented 8 months ago

Are we going to support DDL alter soon ? It would be good, if we can add support for these alters. requesting you to please work on this soon..

xnuinside commented 8 months ago

@rmorais01 thanks for opening this issue & explicit examples, required changes will be in this PR https://github.com/xnuinside/simple-ddl-parser/pull/225 @abhishek0102 I will finish it today and release in version 0.32.0

xnuinside commented 8 months ago

@abhishek0102 @rmorais01 all changes released in version 0.32.0, tests added here - https://github.com/xnuinside/simple-ddl-parser/blob/main/tests/test_alter_statements.py#L1778. If will be needed something else - feel free to open new issues & thanks one more time!

abhishek0102 commented 8 months ago

@xnuinside thanks alot.