> What I'm looking to do is make it so > connection.columns sets the primary flag so that when I do a db_schema_dump > I can have the create_table have the correct :primary_key value (assuming > the default "id" isn't being used). > > So if I have: > > CREATE TABLE Users ( > UserID int NOT NULL IDENTITY(1,1) PRIMARYKEY, > Name varchar(100) > ) > > and do a db_schema_dump I want to get: > > create_table "Users", :primary_key => "UserID" do |t| > t.column "Name", :string, :limit => 100 > end > > Currently since the connection.columns doesn't set the primary flag for the > primary key column and since SchemaDumper doesn't use ActiveRecord::Base > (which would set the primary flag) I get: > > create_table "users", :id => false do |t| > t.column "UserID", :integer, :null => false > t.column "Name", :string, :limit => 100 > end > Do people agree that this would be a good change? Can anyone offer insight > into what other adapters might be able to do here?
To me it's pretty clear the schema dumper should dump the whole schema, including information about primary keys. However, I don't think the right way to get this info is through ActiveRecord::Base.primary_key. ActiveRecord::Base.primary_key uses declarations in the model classes (set_primary_key, primary_key_prefix_type) to determine the primary key. However, the schema dumper gets all of its information directly from the database. To work correctly, I think the schema dumper should get primary key info directly from the db as well, though this would mean writing new code for most, if not all the adapters. One added benefit if this was done, might be that primary key declarations could be removed from the model code completely, making things simpler for those using quirky primary keys. Hope this is clear, Tom -- email : tom at popdog.net
_______________________________________________ Rails-core mailing list [email protected] http://lists.rubyonrails.org/mailman/listinfo/rails-core
