Please sign in to comment.
Refactor schema parsing, include primary key on PostgreSQL and MySQL
This commit refactors the schema parsing. It eliminates the shared INFORMATION_SCHEMA based parsing that worked OK on PostgreSQL and very slowly on MySQL. The Database#schema public method has been kept, but the other shared private methods were removed, with the exception of schema_column_type for mapping database types to ruby types. MySQL, PostgreSQL, and SQLite schema parsing all include the :primary_key entry that shows whether the column is (part of) the primary key. PostgreSQL now uses the pg_* system catalogs directly, instead of the information_schema. MySQL uses the DESCRIBE syntax to get a table description. SQLite was cleaned up slightly, but still uses the table_info pragma. The shared Database#schema method now falls back to getting the schema separately for each table if it can't get the schema for all tables at once, assuming it knows how to get the schema for a single table and it knows how to get a list of tables. PostgreSQL now supports specifying a qualified table name (including schema) in the call to Database#schema. Before, the schema had to be specified explicity using the :schema option, which means it didn't work correctly with models. It still defaults to the public schema if no schema is specified (either explicitly or implicitly). This means that DB.schema(:s__t) now gives column information for table t in schema s. The :numeric_precision and :max_chars entries are no longer included in the hashes returned by schema. You should be able to get the same or similar information using the :db_type entry, which now includes specified lengths (e.g. varchar(255)). Since primary keys can now be parsed from the schema, use the schema information to set primary keys for schema models. In addition, this commit makes schema changing methods such as drop_table and alter_table remove the cached schema entry. It also has a small fix to drop_view to allow dropping multiple views at once, so it works just like drop_table. Additionally, it quotes the view names. The schema hash keys are now always supposed to be symbols. This commit also changes some specs to remove the use of set_schema, and it adds integration tests to test schema parsing of primary keys, NULL/NOT NULL, and defaults. This commit makes MySQL Database#tables work on JDBC as well as using the native adapter, by using the SHOW TABLES syntax.
- Loading branch information...
Showing with 279 additions and 232 deletions.
- +16 −0 CHANGELOG
- +0 −5 lib/sequel_core/adapters/mysql.rb
- +17 −21 lib/sequel_core/adapters/shared/mysql.rb
- +65 −8 lib/sequel_core/adapters/shared/postgres.rb
- +6 −22 lib/sequel_core/adapters/shared/sqlite.rb
- +13 −5 lib/sequel_core/database/schema.rb
- +23 −80 lib/sequel_core/schema/sql.rb
- +3 −0 lib/sequel_model/base.rb
- +2 −2 spec/adapters/mysql_spec.rb
- +5 −4 spec/adapters/postgres_spec.rb
- +1 −1 spec/adapters/sqlite_spec.rb
- +47 −54 spec/integration/eager_loader_test.rb
- +28 −4 spec/integration/schema_test.rb
- +36 −25 spec/sequel_core/schema_spec.rb
- +1 −1 spec/sequel_model/hooks_spec.rb
- +1 −0 spec/sequel_model/model_spec.rb
- +7 −0 spec/sequel_model/record_spec.rb
- +8 −0 spec/sequel_model/spec_helper.rb
Oops, something went wrong.