[cl-migrations-devel] first test ...

Nicolas Lamirault lam at tuxfamily.org
Thu Apr 19 20:16:07 UTC 2007


hello,
i'm trying your cl-migrations tool.
it seems very interesting ...
i've some remarks :


1 - for cl-migrations' newbie (like me), it could be interesting
to write  in your example  page (on cl.net)  that we could  change the
*migration-dir* :

CL-USER> (setf cl-migrations:*migration-dir* "/home/nicolas/tmp/")

2 - i try to creates the 1-.... file :

CL-USER> (cl-migrations:generate "add-employees-table")
junk in string "foo.lisp"
   [Condition of type SB-INT:SIMPLE-PARSE-ERROR]

Restarts:
 0: [ABORT] Return to SLIME's top level.
 1: [ABORT] Exit debugger, returning to top level.

Backtrace:
  0: (PARSE-INTEGER "foo.lisp")
  1: (CL-MIGRATIONS::GET-LATEST-MIGRATION)
  2: (CL-MIGRATIONS:GENERATE "add-employees-table")
  3: (SB-INT:SIMPLE-EVAL-IN-LEXENV
      (CL-MIGRATIONS:GENERATE "add-employees-table")
      #<NULL-LEXENV>)


the error comes from  that i've got a /home/nicolas/tmp/foo.lisp files
and from this method (parse-integer) :

(defun get-migration-number (file)
  (parse-integer 
   (subseq (file-namestring file) 0 (search "-" (file-namestring file)))))

i don't really how correct this ? throw an error ? return nil ? ...


3- try to creates the database model :

CL-USER> (cl-migrations:generate "add-employees-table")
"1-add-employees-table.lisp"

CL-USER> (cl-migrations:migrate)
WARNING: Exiting - .migrate.conf not found in the home directory
A database error occurred: NIL / NIL
  NIL is not a database.
   [Condition of type CLSQL-SYS:SQL-DATABASE-ERROR]

Restarts:
 0: [ABORT] Return to SLIME's top level.
 1: [ABORT] Exit debugger, returning to top level.

Backtrace:
  0: (CLSQL-SYS::SIGNAL-NO-DATABASE-ERROR NIL)
  1: (CLSQL-SYS::SIGNAL-NO-DATABASE-ERROR NIL)
  2: (CLSQL-SYS:SELECT
      CL-MIGRATIONS::VERSION
      :FROM
      "schema_info"
      :FLATP
      T
      :FIELD-NAMES
      NIL)
  3: (CL-MIGRATIONS::GET-DB-VERSION)
  4: (CL-MIGRATIONS:MIGRATE :VERSION NIL)
  5:       (SB-INT:SIMPLE-EVAL-IN-LEXENV       (CL-MIGRATIONS:MIGRATE)
  #<NULL-LEXENV>)
  6: (SWANK::EVAL-REGION
      "(cl-migrations:migrate)
     "
      T)

i think i've got a problem with (read-specs)


4- creates the database model with default configuration

CL-USER> (cl-migrations:generate "add-employees-table")

Setting up migrations directory: "/home/nicolas/tmp/migrations/"

The path
  #P"/home/nicolas/tmp/migrations/1-add-employees-table.lisp"
does not exist.
   [Condition of type SB-INT:SIMPLE-FILE-ERROR]

Restarts:
 0: [ABORT] Return to SLIME's top level.
 1: [ABORT] Exit debugger, returning to top level.

i've got this on my .migrate.conf file :

((:mysql ("localhost" "test" "user" "user"))
 (:migration-dir ("/home/nicolas/tmp/migrations/")))

in the "generate" method, i think this could correct the problem :

(ensure-directories-exist
  (directory-namestring #p"/home/nicolas/tmp/migrations/1-add-employees-table.lisp"))


5- Database model 

CL-USER> (ensure-directories-exist
            (directory-namestring #p"/home/nicolas/tmp/migrations/1-add-employees-table.lisp"))
"/home/nicolas/tmp/migrations/"
T

CL-USER> (cl-migrations:generate "add-employees-table")
"1-add-employees-table.lisp"

CL-USER> (cl-migrations:migrate)

Setting up migrations directory: "/home/nicolas/tmp/migrations/"
; loading system definition from
; /home/nicolas/.sbcl/systems/clsql-mysql.asd into #<PACKAGE "ASDF0">
; registering #<SYSTEM :CLSQL-MYSQL {B6E3E39}> as CLSQL-MYSQL
; loading system definition from
; /home/nicolas/.sbcl/systems/clsql-uffi.asd into #<PACKAGE "ASDF0">
; registering #<SYSTEM CLSQL-UFFI {BA36CB9}> as CLSQL-UFFI
Schema table doesn't exist, creating.
Database ready.

Migration #1:
EXEC: "create table employees (id serial, name varchar(100))"
EXEC: "create table products (id serial, name varchar(100))"
While  accessing  database  #<MYSQL-DATABASE localhost/test/root  OPEN
{AA87289}>
  with expression "UPDATE SCHEMA_INFO SET VERSION = 1 WHERE (VERSION =
  0)":
  Error 1146 / Table 'test.SCHEMA_INFO' doesn't exist
  has occurred.
   [Condition of type CLSQL-SYS:SQL-DATABASE-DATA-ERROR]

Restarts:
 0: [ABORT] Return to SLIME's top level.
 1: [ABORT] Exit debugger, returning to top level.

Backtrace:
  0: ((SB-PCL::FAST-METHOD CLSQL-SYS:DATABASE-EXECUTE-COMMAND
       (T CLSQL-MYSQL:MYSQL-DATABASE))
      #<unavailable argument>
      #<unavailable argument>
      "UPDATE SCHEMA_INFO SET VERSION = 1 WHERE (VERSION = 0)"
      #<CLSQL-MYSQL:MYSQL-DATABASE       localhost/test/root      OPEN
  {AA87289}>)
  1: ((LAMBDA
          (SB-PCL::.PV-CELL. SB-PCL::.NEXT-METHOD-CALL. SB-PCL::.ARG0.
           SB-PCL::.ARG1.))
      #<unavailable argument>
      #<unavailable argument>
      "UPDATE SCHEMA_INFO SET VERSION = 1 WHERE (VERSION = 0)"
      #<CLSQL-MYSQL:MYSQL-DATABASE       localhost/test/root      OPEN
  {AA87289}>)
  2: ((SB-PCL::FAST-METHOD CLSQL-SYS:EXECUTE-COMMAND (STRING))
      #<unused argument>
      #<unused argument>
      "UPDATE SCHEMA_INFO SET VERSION = 1 WHERE (VERSION = 0)"
      :DATABASE
      #<CLSQL-MYSQL:MYSQL-DATABASE       localhost/test/root      OPEN
  {AA87289}>)
  3: ((SB-PCL::FAST-METHOD CLSQL-SYS:EXECUTE-COMMAND
       (CLSQL-SYS::%SQL-EXPRESSION))
      #<unused argument>
      #<unused argument>
      #<CLSQL-SYS::SQL-UPDATE UPDATE SCHEMA_INFO SET VERSION = 1 WHERE
  (VERSION = 0)>
      :DATABASE
      #<CLSQL-MYSQL:MYSQL-DATABASE       localhost/test/root      OPEN
  {AA87289}>)



in the database :


mysql> show tables ;
+----------------+
| Tables_in_test |
+----------------+
| employees |
| products |
| schema_info |
+----------------+
3 rows in set (0.00 sec)

mysql> desc products ;
+-------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+----------------+
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(100) | YES | | NULL | |
+-------+---------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

mysql> desc employees ;
+-------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------+------+-----+---------+----------------+
| id | bigint(20) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(100) | YES | | NULL | |
+-------+---------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)


mysql> UPDATE SCHEMA_INFO SET VERSION = 1 WHERE (VERSION = 0);
ERROR 1146 (42S02): Table 'test.SCHEMA_INFO' doesn't exist


mysql> UPDATE schema_info SET VERSION = 1 WHERE (VERSION = 0);
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0


with mysql the problem comes from the table name.


i've got  a question  about this  tool and the  Ror equivalent  : what
about def-view-class ?
in ror, you creates the SQL model and you generate objects wrapper ?
in some  project, i use def-view-class  and i generate  the SQL tables
from theses objects ...

i thinks it's a great tool ...
i'll use it in some of my projects 


-- 
Nicolas Lamirault



More information about the Cl-migrations-devel mailing list