Skip to content

yshrsmz/sqlstitch

Repository files navigation

sqlstitch

sqlstitch is a command-line tool that reads SQL files, sorts them based on their foreign key constraints, and prints the sorted SQL statements to the standard output. The output is safe to execute as is, which means it can be directly used to create or modify a database schema.

$ sqlstitch --help
Usage: sqlstich [OPTIONS] <FILES>...

Arguments:
  <FILES>...  Input files to process

Options:
  -v, --verbose  Prints debug information
  -h, --help     Print help
  -V, --version  Print version

Usage

You can use sqlstitch by providing it with one or more SQL files as arguments. Here's the basic usage:

$ sqlstich <FILES>...

For example, if you have a directory named schema containing your SQL files, you can sort all of them and write the output to a new SQL file like this:

$ sqlstich schema/*.sql > sorted_schema.sql

This will create a new file named sorted_schema.sql containing the sorted SQL statements.

Supported SQL Statements

Currently, sqlstitch supports the following SQL statements:

  • CREATE TABLE: This statement is used to create a new table in a database.
  • CREATE INDEX: This statement is used to create an index on one or more columns of a table.

Please note that other SQL statements present in the provided files will be ignored by sqlstitch in its current version. We are actively working on expanding the list of supported SQL statements. Stay tuned for updates!

Installation

To install sqlstitch, please refer to the releases page. You'll find the latest version of sqlstitch there, along with instructions on how to install it.

Contributing

If you'd like to contribute to the development of sqlstitch, we'd love to have your help! You can start by checking out our open issues. If you find one that you'd like to work on, feel free to fork the repository and submit a pull request.

License

sqlstitch is licensed under the Apache-2.0 License.