class
CQL::SchemaDump
- CQL::SchemaDump
- Reference
- Object
Overview
The SchemaDump class provides functionality to reverse-engineer a database schema
and generate a CQL schema definition file by inspecting existing database tables,
columns, indexes, and foreign keys.
Example Dumping a SQLite database schema
dumper = CQL::SchemaDump.new(CQL::Adapter::SQLite, "sqlite3://db/myapp.db")
dumper.dump_to_file("src/schemas/myapp_schema.cr", :MyApp, :myapp)
Example Dumping a PostgreSQL database schema
dumper = CQL::SchemaDump.new(CQL::Adapter::Postgres, "postgresql://user:pass@localhost/mydb")
dumper.dump_to_file("src/schemas/production_schema.cr", :ProductionDB, :production_db)
Defined in:
schema_dump.crConstant Summary
-
DEFAULT_SCHEMA_DUMP_FILE_PATH =
"./src/schemas/schema.cr" -
Log =
CQL.config.logger
Constructors
-
.new(adapter : Adapter, uri : String)
Initialize the schema dumper - @param adapter [Adapter] The database adapter to use - @param uri [String] The database connection URI - @raise [Error] If connection fails
Class Method Summary
-
.from_schema(schema : CQL::Schema)
Create a SchemaDump instance from an existing CQL::Schema This is useful for migration integration where you already have a schema instance - @param schema [CQL::Schema] The existing schema instance - @return [SchemaDump] New SchemaDump instance
-
.open(schema : CQL::Schema, &)
Yields a dumper for schema's database and closes its connections afterwards.
Instance Method Summary
- #adapter : Adapter
-
#close
Close the database connection
-
#dump_to_file(file_path : String = DEFAULT_SCHEMA_DUMP_FILE_PATH, schema_name : Symbol = :AppSchema, schema_symbol : Symbol = :app_schema)
Dump the database schema to a file - @param file_path [String] Path where to save the schema file - @param schema_name [Symbol] Name for the schema constant - @param schema_symbol [Symbol] Symbol name for the schema
-
#generate_schema_content(schema_name : Symbol, schema_symbol : Symbol) : String
Generate the schema content as a string - @param schema_name [Symbol] Name for the schema constant - @param schema_symbol [Symbol] Symbol name for the schema - @return [String] The generated schema content
- #uri : String
Constructor Detail
Initialize the schema dumper
- @param adapter [Adapter] The database adapter to use
- @param uri [String] The database connection URI
- @raise [Error] If connection fails
Class Method Detail
Create a SchemaDump instance from an existing CQL::Schema This is useful for migration integration where you already have a schema instance
- @param schema [CQL::Schema] The existing schema instance
- @return [SchemaDump] New SchemaDump instance
Yields a dumper for schema's database and closes its connections afterwards.
- @return the block's value
Instance Method Detail
Dump the database schema to a file
- @param file_path [String] Path where to save the schema file
- @param schema_name [Symbol] Name for the schema constant
- @param schema_symbol [Symbol] Symbol name for the schema
Generate the schema content as a string
- @param schema_name [Symbol] Name for the schema constant
- @param schema_symbol [Symbol] Symbol name for the schema
- @return [String] The generated schema content