better_structure_sql 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +69 -0
- data/README.md +218 -686
- data/app/CLAUDE.md +12 -0
- data/app/controllers/better_structure_sql/application_controller.rb +71 -31
- data/app/controllers/better_structure_sql/schema_versions_controller.rb +94 -153
- data/app/helpers/better_structure_sql/schema_versions_helper.rb +48 -24
- data/app/views/better_structure_sql/schema_versions/index.html.erb +46 -49
- data/app/views/better_structure_sql/schema_versions/show.html.erb +73 -120
- data/app/views/layouts/better_structure_sql/application.html.erb +27 -18
- data/config/routes.rb +1 -1
- data/lib/CLAUDE.md +73 -0
- data/lib/better_structure_sql/adapters/base_adapter.rb +16 -1
- data/lib/better_structure_sql/adapters/mysql_adapter.rb +396 -364
- data/lib/better_structure_sql/adapters/postgresql_adapter.rb +574 -478
- data/lib/better_structure_sql/adapters/registry.rb +18 -15
- data/lib/better_structure_sql/adapters/sqlite_adapter.rb +221 -474
- data/lib/better_structure_sql/configuration.rb +9 -2
- data/lib/better_structure_sql/creation_order.rb +157 -0
- data/lib/better_structure_sql/dependency_resolver.rb +4 -2
- data/lib/better_structure_sql/dumper.rb +173 -315
- data/lib/better_structure_sql/engine.rb +50 -4
- data/lib/better_structure_sql/file_writer.rb +108 -97
- data/lib/better_structure_sql/generators/base.rb +31 -4
- data/lib/better_structure_sql/generators/comment_generator.rb +16 -12
- data/lib/better_structure_sql/generators/domain_generator.rb +8 -6
- data/lib/better_structure_sql/generators/extension_generator.rb +7 -2
- data/lib/better_structure_sql/generators/foreign_key_generator.rb +14 -4
- data/lib/better_structure_sql/generators/index_generator.rb +0 -20
- data/lib/better_structure_sql/generators/materialized_view_generator.rb +17 -2
- data/lib/better_structure_sql/generators/sequence_generator.rb +13 -5
- data/lib/better_structure_sql/generators/table_generator.rb +164 -47
- data/lib/better_structure_sql/generators/type_generator.rb +25 -14
- data/lib/better_structure_sql/generators/view_generator.rb +12 -8
- data/lib/better_structure_sql/introspection/extensions.rb +1 -14
- data/lib/better_structure_sql/introspection/foreign_keys.rb +1 -14
- data/lib/better_structure_sql/introspection/functions.rb +1 -14
- data/lib/better_structure_sql/introspection/indexes.rb +1 -14
- data/lib/better_structure_sql/introspection/sequences.rb +1 -14
- data/lib/better_structure_sql/introspection/tables.rb +1 -14
- data/lib/better_structure_sql/introspection/triggers.rb +1 -14
- data/lib/better_structure_sql/introspection/types.rb +1 -14
- data/lib/better_structure_sql/introspection/views.rb +2 -19
- data/lib/better_structure_sql/introspection.rb +12 -1
- data/lib/better_structure_sql/migration_patch.rb +39 -139
- data/lib/better_structure_sql/railtie.rb +53 -56
- data/lib/better_structure_sql/schema_loader.rb +107 -86
- data/lib/better_structure_sql/schema_version.rb +3 -2
- data/lib/better_structure_sql/schema_versions.rb +70 -71
- data/lib/better_structure_sql/version.rb +1 -1
- data/lib/better_structure_sql/zip_generator.rb +43 -6
- data/lib/better_structure_sql.rb +2 -1
- data/lib/generators/better_structure_sql/migration_generator.rb +1 -1
- data/lib/generators/better_structure_sql/templates/README +17 -34
- data/lib/tasks/better_structure_sql.rake +19 -40
- metadata +9 -147
- data/config/database.yml +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: df4e9f69e6c07d4dc7a4a9b7dbebcc911741768f7d992b64ce435827b5146b30
|
|
4
|
+
data.tar.gz: 133f05c44a4cf8f24062dab03e382da2e024d4eaf0f43c3154ef02921cccbbb7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40a25f99dba885457558f8a1a33d5ba5116d891be48da01bab5104920ede29b25df680cb96da01dc8dca1398c38e5e71a45081b5210a7ec463f2cd4f50870829
|
|
7
|
+
data.tar.gz: e067fc60a1456a2abdaea5d6b059b0f68bfe961f3942ae816d63f8cfc06a9b4bdc8deea6c62e4a2b79d05841021d8ff70d759e1775dbbdd534d9e5b032d3b6c5
|
data/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,80 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-11-23
|
|
11
|
+
|
|
12
|
+
### Upgrading
|
|
13
|
+
|
|
14
|
+
1. **Web UI access (breaking).** Outside development and test the engine now answers `403 Forbidden` until access control is declared. In `config/initializers/better_structure_sql.rb` add one of:
|
|
15
|
+
- `BetterStructureSql::Engine.authentication_handled_by_routes!` when the routes that mount the engine already restrict access (Devise `authenticate`, a `constraints` block);
|
|
16
|
+
- `BetterStructureSql::Engine.authenticate_with { |controller| ... }` returning truthy to allow the request.
|
|
17
|
+
|
|
18
|
+
An override of `authenticate_access!` keeps working. A separate `before_action` added through `class_eval` needs one of the two calls as well. See [docs/features/web-ui.md](docs/features/web-ui.md).
|
|
19
|
+
2. **Ruby and Rails (breaking).** The minimum versions were raised: see `required_ruby_version` and the `rails` dependency in [`better_structure_sql.gemspec`](better_structure_sql.gemspec).
|
|
20
|
+
3. **Dump again and commit the diff.** Output changed format once on every database (see Changed), and multi-file dumps are re-chunked.
|
|
21
|
+
4. **MySQL and MariaDB: load through the gem.** Set `config.replace_default_load = true` or use `rails db:schema:load_better`. Rails' own `structure.sql` load pipes the file through the `mysql` client, which needs `DELIMITER` directives the dump does not contain.
|
|
22
|
+
5. **`Dumper#dump` with schema versions enabled** now stores a version and raises if it cannot. Migrate the versions table, or call `dump(store_version: false)`.
|
|
23
|
+
6. **`db:schema:restore` replaces the schema (breaking).** It purges the database before loading the stored version: every table and all data are dropped, the stored schema versions included. It needs `CONFIRM=1` (`CONFIRM=1 rails db:schema:restore[5]`) and runs Rails' protected-environment check, so production is refused unless `DISABLE_DATABASE_ENVIRONMENT_CHECK=1` is set. Scripts that call the task must pass `CONFIRM=1`, and must not expect existing objects or data to survive.
|
|
24
|
+
|
|
10
25
|
### Added
|
|
26
|
+
- PostgreSQL: partitioned tables (`PARTITION BY`, `PARTITION OF ... FOR VALUES`), identity columns, generated columns, range types, exclusion constraints, procedures, view options, column collations, `OWNED BY` for serial sequences
|
|
27
|
+
- PostgreSQL: composite, `MATCH FULL`, `DEFERRABLE` and `NOT VALID` foreign keys; `NOT VALID` check constraints; domains with defaults, `NOT NULL` and every check
|
|
28
|
+
- PostgreSQL: views are written in dependency order
|
|
29
|
+
- PostgreSQL: table inheritance (`INHERITS`, with only the child's own columns and constraints; parents are written first), `UNLOGGED` tables, table storage parameters (`WITH (fillfactor=70)`), comments on procedures
|
|
30
|
+
- MySQL: views are written in dependency order (`information_schema.VIEW_TABLE_USAGE` on MySQL 8.0.13+, the view definition on MariaDB)
|
|
31
|
+
- MySQL: the `trilogy` driver (the registry requires the gem matching the connection, `mysql2` or `trilogy`) and MariaDB servers
|
|
32
|
+
- MySQL: `CHECK` constraints (with `NOT ENFORCED`), `AUTO_INCREMENT`, `ON UPDATE`, expression defaults, generated columns, column collations, `ENGINE` / `COLLATE` table options
|
|
33
|
+
- MySQL: full index definitions: `FULLTEXT`, `SPATIAL`, prefix lengths, `DESC` key parts, functional key parts, `INVISIBLE`
|
|
34
|
+
- SQLite: `AUTOINCREMENT`, `WITHOUT ROWID`, `STRICT`, collations, unnamed `CHECK` constraints, table-level `UNIQUE`, composite primary keys, generated columns, partial and expression indexes
|
|
35
|
+
- Composite foreign keys on MySQL and SQLite (one entry per key, columns in key order)
|
|
36
|
+
- Integration apps: `bss:round_trip` in `integration_mysql/` and `integration_sqlite/` (dump, load into an empty database, dump again, compare dumps and the database's own DDL; `ROUND_TRIP_LAYOUT=multi_file` for the directory layout). CI runs it on MySQL and MariaDB with both drivers and on SQLite: see the `integration-*` jobs in `.github/workflows/ci.yml`
|
|
37
|
+
- Web UI: `BetterStructureSql::Engine.authenticate_with` and `BetterStructureSql::Engine.authentication_handled_by_routes!`
|
|
38
|
+
- Web UI: the version list is paginated with `?page=`
|
|
39
|
+
- Multiple databases: non-primary databases are dumped and loaded by the gem at the Rails path (`db/<name>_structure.sql`); `SCHEMA=` is honoured
|
|
40
|
+
- `SchemaVersions.store_current` accepts `config:`
|
|
41
|
+
- `SchemaVersions.restore(version, db_config:)` (purge, load, record), `SchemaLoader#load_and_record` (load, then record the environment and `schema_sha1` in `ar_internal_metadata`) and `SchemaLoader.schema_sha1(path)` (checksum of a schema file or directory)
|
|
42
|
+
- `db:schema:restore` works on MySQL and SQLite and for `rb` versions
|
|
43
|
+
- `llms.txt`, `CONTRIBUTING.md`, `SECURITY.md`, `CODE_OF_CONDUCT.md`, issue and pull request templates
|
|
11
44
|
|
|
12
45
|
### Changed
|
|
46
|
+
- **BREAKING**: the web UI fails closed outside development and test (see Upgrading)
|
|
47
|
+
- **BREAKING**: the minimum Ruby and Rails versions were raised (see the gemspec)
|
|
48
|
+
- **BREAKING**: `db:schema:restore` replaces the schema: it purges the database, loads the stored version, then records the environment and `schema_sha1` in `ar_internal_metadata`. It requires `CONFIRM=1` and runs Rails' protected-environment check (production is refused unless `DISABLE_DATABASE_ENVIRONMENT_CHECK=1`). All data and the stored versions in that database are lost. Previously the task executed the version on top of the existing schema, which could not succeed on PostgreSQL (see Upgrading)
|
|
49
|
+
- `db:schema:store` and `SchemaVersions.store_current` never delete the multi-file directory; the `keep_directory:` argument is gone
|
|
50
|
+
- MySQL output format: column types and defaults are written as the server reports them (`int unsigned`, `datetime(6)`, `tinyint(1)`), views come from `SHOW CREATE VIEW` and no longer carry the database name
|
|
51
|
+
- SQLite output format: tables, indexes and views are the original statements from `sqlite_master`, verbatim; of the PRAGMAs only `application_id`, `auto_vacuum` and `user_version` are written, and only when non-zero
|
|
52
|
+
- Foreign key statements quote every identifier
|
|
53
|
+
- PostgreSQL output format: identifiers are always double-quoted, Rails timestamps are written as `timestamp(6)`, sequences carry `AS integer` where they are not `bigint`
|
|
54
|
+
- Multi-file chunking counts the blank line between objects, so files are split at slightly different points
|
|
55
|
+
- Multi-file dumps remove files and directories left by a previous dump, and remove `_manifest.json` when `generate_manifest` is off
|
|
56
|
+
- Dump files are written atomically (temporary file, then rename)
|
|
57
|
+
- Introspection errors raise instead of producing an empty section with a warning
|
|
58
|
+
- `SchemaVersions.store_current` raises `SchemaVersionError` when no dump exists; `db:schema:store` then exits 1
|
|
59
|
+
- `ZipGenerator.extract_to_directory` raises `ZipError` on an unsafe path or exceeded limits (counted on inflated bytes) and overwrites existing files
|
|
60
|
+
- `search_path` must not be blank
|
|
61
|
+
- Web UI: text downloads are `text/plain; charset=utf-8`, every response is `Cache-Control: no-store`, ids must be numeric, the version column is labelled "Database"
|
|
62
|
+
- Documentation rewritten against the code; stale planning and status documents removed
|
|
13
63
|
|
|
14
64
|
### Fixed
|
|
65
|
+
- PostgreSQL: enums, composites, ranges and domains are created in dependency order, and a domain whose check calls a function after that function (a composite using a later-named enum or a domain, or a domain check calling a function, no longer fails to load)
|
|
66
|
+
- PostgreSQL: a function whose `BEGIN ATOMIC` body uses a sequence is created after the sequence
|
|
67
|
+
- PostgreSQL: constraint columns and column comments whose names contain a comma or a dot are no longer split apart
|
|
68
|
+
- Dependency sorting is linear in the number of objects and dependencies (20,000 objects took seconds)
|
|
69
|
+
- SQLite: a dump containing views loads (views were written as `CREATE OR REPLACE VIEW`, which SQLite rejects)
|
|
70
|
+
- SQLite: the `schema_migrations` rows are dumped, so a loaded dump has no pending migrations
|
|
71
|
+
- MySQL: a composite foreign key is one statement instead of one per column
|
|
72
|
+
- MariaDB: a view whose column alias, table alias or qualifier is named like another view no longer makes that view count as a dependency, which could create the view before a view it reads
|
|
73
|
+
- MySQL: triggers sharing a table, timing and event keep their firing order (`ACTION_ORDER`) across a dump and load
|
|
74
|
+
- MySQL: loading no longer appends Rails query log tags to routine and trigger bodies
|
|
75
|
+
- `Dumper#dump(store_version: true)` now stores a version (deduplicated, with a ZIP in multi-file mode) instead of failing silently
|
|
76
|
+
- `rails db:schema:load` with `replace_default_load` records the schema checksum in `ar_internal_metadata`
|
|
77
|
+
- `config.active_record.maintain_test_schema = false` is respected
|
|
78
|
+
- `maintain_test_schema!` with a schema directory: with `replace_default_dump` or `replace_default_load` on, Rails' own refresh runs unchanged; otherwise the directory at `output_path` is loaded through Rails' `load_schema`, which records the environment and `schema_sha1`, and pending migrations are checked
|
|
79
|
+
- `rails db:schema:load` loads a schema directory even with `replace_default_load` off
|
|
80
|
+
- `db:schema:load_better` records the environment and `schema_sha1` in `ar_internal_metadata`, so a later `db:drop` no longer raises `NoEnvironmentInSchemaError`
|
|
81
|
+
- Web UI: the empty version list names `rails db:schema:store`
|
|
82
|
+
- `db:schema:cleanup` no longer calls `exit`
|
|
83
|
+
- The web UI displays inline content up to its 1 MB limit
|
|
15
84
|
|
|
16
85
|
## [0.2.2] - 2025-11-23
|
|
17
86
|
|