lobos icon indicating copy to clipboard operation
lobos copied to clipboard

Maintain column order from migration, even with 10+ columns

Open hotwoofy opened this issue 13 years ago • 3 comments

Currently, up to 9 columns, the correct order is maintained in the table definition (first listing below). However, upon hitting 10 columns, the order is lost (second listing). I've forced the column map to now be ordered, and now any number of columns can be added without losing the order (third listing). I've done this by taking a dependency on ordered, I hope that's acceptable.

The driver for this was ClojureQL's implementation of JDBC's .getGeneratedKeys, which expects a primary key column to be the first that it finds when inserting.

user> (pprint (table :test
                     (integer :col1)
                     (integer :col2)
                     (integer :col3)
                     (integer :col4)
                     (integer :col5)
                     (integer :col6)
                     (integer :col7)
                     (integer :col7)
                     (integer :col8)
                     (integer :col9)))
{:name :test,
 :columns
 {:col1
  {:cname :col1,
   :data-type {:name :integer, :args [], :options {}},
   :default nil,
   :auto-inc nil,
   :not-null nil,
   :others ()},
  .
  .
  .
  {:cname :col9,
   :data-type {:name :integer, :args [], :options {}},
   :default nil,
   :auto-inc nil,
   :not-null nil,
   :others ()}},
 :constraints {},
 :indexes {}}
user> (pprint (table :test
                     (integer :col1)
                     (integer :col2)
                     (integer :col3)
                     (integer :col4)
                     (integer :col5)
                     (integer :col6)
                     (integer :col7)
                     (integer :col7)
                     (integer :col8)
                     (integer :col9)
                     (integer :col10)))
{:name :test,
 :columns
 {:col6
  {:cname :col6,
   :data-type {:name :integer, :args [], :options {}},
   :default nil,
   :auto-inc nil,
   :not-null nil,
   :others ()},
  :col7
  {:cname :col7,
   :data-type {:name :integer, :args [], :options {}},
   :default nil,
   :auto-inc nil,
   :not-null nil,
   :others ()},
  :col4
  {:cname :col4,
   :data-type {:name :integer, :args [], :options {}},
   :default nil,
   :auto-inc nil,
   :not-null nil,
   :others ()},
  :col5
  .
  .
  .
user> (pprint (table :test
                     (integer :col1)
                     (integer :col2)
                     (integer :col3)
                     (integer :col4)
                     (integer :col5)
                     (integer :col6)
                     (integer :col7)
                     (integer :col7)
                     (integer :col8)
                     (integer :col9)
                     (integer :col10)))
{:name :test,
 :columns
 {:col1
  {:cname :col1,
   :data-type {:name :integer, :args [], :options {}},
   :default nil,
   :auto-inc nil,
   :not-null nil,
   :others ()},
  :col2
  .
  .
  .
  {:cname :col10,
   :data-type {:name :integer, :args [], :options {}},
   :default nil,
   :auto-inc nil,
   :not-null nil,
   :others ()}},
 :constraints {},
 :indexes {}}

hotwoofy avatar Dec 14 '12 21:12 hotwoofy

Looks good, I'll probably work a bit on Lobos during the holidays and merge it then. Thanks for your patience.

budu avatar Dec 17 '12 22:12 budu

@budu any update on this issue? I really like Lobos but I'm considering other options because of this issue :(

jplaza avatar Jan 18 '13 04:01 jplaza

@jplaza one workaround in the meantime is to use my fork, the other is to write your migrations for large tables in two steps - first create it with just the ID, the alter it to append the rest of the columns.

hotwoofy avatar Jan 18 '13 11:01 hotwoofy