diff --git a/doc/reflection.rdoc b/doc/reflection.rdoc index 907c26b19..0432a9a6d 100644 --- a/doc/reflection.rdoc +++ b/doc/reflection.rdoc @@ -59,6 +59,7 @@ The hash may also contain entries for: Database#schema takes a table symbol and returns column information in an array with each element being an array with two elements. The first elements of the subarray is a column symbol, and the second element is a hash of information about that column. The hash should include the following keys: :allow_null :: Whether NULL/nil is an allowed value for this column. Used by the Sequel::Model typecasting code. +:comment:: The comment of the column. :db_type :: The type of column the database provided, as a string. Used by the schema_dumper plugin for a more specific type translation. :default :: The default value of the column, as either a string or nil. Uses a database specific format. Used by the schema_dumper plugin for converting to a ruby value. :primary_key :: Whether this column is one of the primary key columns for the table. Used by the Sequel::Model code to determine primary key columns. diff --git a/lib/sequel/adapters/shared/mysql.rb b/lib/sequel/adapters/shared/mysql.rb index 57414faa4..853227b85 100644 --- a/lib/sequel/adapters/shared/mysql.rb +++ b/lib/sequel/adapters/shared/mysql.rb @@ -567,7 +567,7 @@ def schema_parse_table(table_name, opts) im = input_identifier_meth(opts[:dataset]) table = SQL::Identifier.new(im.call(table_name)) table = SQL::QualifiedIdentifier.new(im.call(opts[:schema]), table) if opts[:schema] - metadata_dataset.with_sql("DESCRIBE ?", table).map do |row| + metadata_dataset.with_sql("SHOW FULL COLUMNS FROM ?", table).map do |row| extra = row.delete(:Extra) if row[:primary_key] = row.delete(:Key) == 'PRI' row[:auto_increment] = !!(extra.to_s =~ /auto_increment/i) @@ -577,8 +577,11 @@ def schema_parse_table(table_name, opts) row[:generated] = !!(extra.to_s =~ /VIRTUAL|STORED|PERSISTENT/i) end row[:allow_null] = row.delete(:Null) == 'YES' + row[:collation] = row.delete(:Collation) + row[:comment] = row.delete(:Comment) row[:default] = row.delete(:Default) row[:db_type] = row.delete(:Type) + row[:privileges] = row.delete(:Privileges) row[:type] = schema_column_type(row[:db_type]) row[:extra] = extra [m.call(row.delete(:Field)), row] diff --git a/lib/sequel/adapters/shared/postgres.rb b/lib/sequel/adapters/shared/postgres.rb index 5b128dbce..2eb57298f 100644 --- a/lib/sequel/adapters/shared/postgres.rb +++ b/lib/sequel/adapters/shared/postgres.rb @@ -1075,6 +1075,7 @@ def _schema_ds pg_attribute[:attname].as(:name), SQL::Cast.new(pg_attribute[:atttypid], :integer).as(:oid), SQL::Cast.new(basetype[:oid], :integer).as(:base_oid), + pg_description[:description].as(:comment), SQL::Function.new(:format_type, basetype[:oid], pg_type[:typtypmod]).as(:db_base_type), SQL::Function.new(:format_type, pg_type[:oid], pg_attribute[:atttypmod]).as(:db_type), SQL::Function.new(:pg_get_expr, pg_attrdef[:adbin], pg_class[:oid]).as(:default), @@ -1090,6 +1091,7 @@ def _schema_ds left_outer_join(Sequel[:pg_type].as(:elementtype), :typarray=>Sequel[:pg_type][:oid]). left_outer_join(:pg_attrdef, :adrelid=>Sequel[:pg_class][:oid], :adnum=>Sequel[:pg_attribute][:attnum]). left_outer_join(:pg_index, :indrelid=>Sequel[:pg_class][:oid], :indisprimary=>true). + left_outer_join(:pg_description, :objoid => Sequel[:pg_attribute][:attrelid]). where{{pg_attribute[:attisdropped]=>false}}. where{pg_attribute[:attnum] > 0}. order{pg_attribute[:attnum]}