boss_db
boss_db copied to clipboard
boss_migrate cannot handle "schema_migrations"?
Hi, I was working with boss_db, when I found the db migration is left out from ChicagoBoss (CB), then I also add CB into rebar deps.
What I have done:
1 boss_migrate:make() 2 boss_migrate:run()
In the same erl, boss_db:execute() works well.
What did I do wrong?
boss_migrate:run(app_name_atom).
18:36:22.724 [info] Reading migration file: "/Path/priv/migrations/1413279116_create_table.erl"
** exception exit: {{undef,
[{schema_migrations,module_info,[exports],[]},
{boss_record_lib,dummy_record,1,
[{file,"src/boss_record_lib.erl"},{line,75}]},
{boss_record_lib,database_table,1,
[{file,"src/boss_record_lib.erl"},{line,99}]},
{boss_db_adapter_mysql,table_exists,2,
[{file,
"src/db_adapters/boss_db_adapter_mysql.erl"},
{line,105}]},
{boss_db_controller,handle_call,3,
[{file,"src/boss_db_controller.erl"},{line,192}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,580}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,239}]}]},
After I went for pgsql, everything works.
Why is this issue closed? This is not a fix for the MySql adapter.
@adrianrosian is it something you are able to test?
My colleague was able to reproduce this, I think he also said that he has a fix and will issue a pull request, I will keep you updated
Sorry. By the way, the create_table/2 in adapter for pgsql only works with least expectations.
What do you mean by 'least expectations'?
@davidw
As for create_table/2 in master ()
(1). only four types are supported
column_type_to_sql(auto_increment) -> "SERIAL"; column_type_to_sql(string) -> "VARCHAR"; column_type_to_sql(integer) -> "INTEGER"; column_type_to_sql(datetime) -> "TIMESTAMP".
(2). column option, in effect, only [not_null] | [primary_key] are valid. ([not_null, primary_key] would generate sql "NOT NULLPRIMARY KEY" (sic))
column_options_to_sql(Options) -> [option_to_sql({Option, Args}) || {Option, Args= true} <- proplists:unfold(Options)]. option_to_sql({not_null, true}) -> "NOT NULL"; option_to_sql({primary_key, true}) -> "PRIMARY KEY".
That is all one can expect from create_table; it is enough for "schema_migrations" though.
Oh, that, yes, it does the minimum necessary to handle migrations. Extending it would be cool, but is probably not really a priority right now.
@davidw I saw that. Thank you.
My problem was different:
(cpr@kamyczeq)2> boss_db:table_exists(schema_migrations).
** exception exit: {{undef,[{schema_migrations,module_info,[exports],[]},
{boss_record_lib,dummy_record,1,
[{file,"src/boss_record_lib.erl"},{line,75}]},
{boss_record_lib,database_table,1,
[{file,"src/boss_record_lib.erl"},{line,99}]},
{boss_db_adapter_mysql,table_exists,2,
[{file,"src/db_adapters/boss_db_adapter_mysql.erl"},
{line,105}]},
{boss_db_controller,handle_call,3,
[{file,"src/boss_db_controller.erl"},{line,192}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,580}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]},
{gen_server,call,
[<0.99.0>,{table_exists,schema_migrations},30000]}}
in function gen_server:call/3 (gen_server.erl, line 190)
in call from boss_pool:call/3 (src/boss_pool.erl, line 12)
(cpr@kamyczeq)3> 18:33:14.045 [error] gen_server <0.99.0> terminated with reason: {'module could not be loaded',[{schema_migrations,module_info,[exports],[]},{boss_record_lib,dummy_record,1,[{file,"src/boss_record_lib.erl"},{line,75}]},{boss_record_lib,database_table,1,[{file,"src/boss_record_lib.erl"},{line,99}]},{boss_db_adapter_mysql,table_exists,2,[{file,"src/db_adapters/boss_db_adapter_mysql.erl"},{line,105}]},{boss_db_controller,handle_call,3,[{file,"src/boss_db_controller.erl"},{line,192}]},{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,580}]},{proc_lib,init_p_do_apply,...}]}
18:33:14.045 [error] CRASH REPORT Process <0.99.0> with 2 neighbours exited with reason: call to undefined function schema_migrations:module_info(exports) in gen_server:terminate/6 line 737
18:33:14.045 [error] Supervisor {<0.97.0>,poolboy_sup} had child boss_db_controller started with {boss_db_controller,start_link,undefined} at <0.99.0> exit with reason call to undefined function schema_migrations:module_info(exports) in context child_terminated
The table_exists
from MySQL adapter expects model name which will never work with schema_migrations
table. I've attempted to fix it (see aforementioned pull request).
My problem with Mysql:
> boss_migrate:run(address).
09:55:52.987 [info] Reading migration file: "/home/bunlong/workspace/my_project/geekhmerlab/chicagoboss/addressbook/priv/migrations/1420682718_address.erl"
** exception exit: {{undef,[{boss_db_adapter_mock,table_exists,
[undefined,schema_migrations],
[]},
{boss_db_controller,handle_call,3,
[{file,"src/boss_db_controller.erl"},{line,188}]},
{gen_server,try_handle_call,4,
[{file,"gen_server.erl"},{line,607}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,639}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]},
{gen_server,call,
[<0.293.0>,{table_exists,schema_migrations},30000]}}
in function gen_server:call/3 (gen_server.erl, line 190)
in call from boss_pool:call/3 (src/boss_pool.erl, line 12)
in call from boss_db:create_migration_table_if_needed/0 (src/boss_db.erl, line 122)
in call from boss_db:migrate/1 (src/boss_db.erl, line 108)
> 09:55:52.989 [error] gen_server <0.293.0> terminated with reason: call to undefined function boss_db_adapter_mock:table_exists/2 from boss_db_controller:handle_call/3 line 188
09:55:52.989 [error] CRASH REPORT Process <0.293.0> with 2 neighbours exited with reason: call to undefined function boss_db_adapter_mock:table_exists(undefined, schema_migrations) in gen_server:terminate/7 line 804
09:55:52.990 [error] Supervisor {<0.100.0>,poolboy_sup} had child boss_db_controller started with {boss_db_controller,start_link,undefined} at <0.293.0> exit with reason call to undefined function boss_db_adapter_mock:table_exists(undefined, schema_migrations) in context child_terminated
Please help me to fix it. Thank you!
boss_db_adapter_mock
Offhand, that doesn't look like Mysql...
@davidw: So how can I fix it Sir?
You should probably configure CB to use Mysql. Or, even better, use Postgres :-)
@davidw: Yes I've already configured CB to use Mysql. I can connect to Mysql but I can't run migrate. :(
hi try manually creating the table of "schema_migrations" with the column definitions you may find in one boss_db src file.
ÔÚ 2015Äê1ÔÂ9ÈÕ£¬09:23£¬Bunlong Ryan [email protected] дµÀ£º
@davidw: Yes I've already configured CB to use Mysql. I can connect to Mysql but I can run migrate. :(
¡ª Reply to this email directly or view it on GitHub.
@Bunlong "schema_migrations": id, version (varchar), migrated_at (like timestamp).
@liuzhen: I am a newbie with Chicagoboss, Could you details more than this? Thank you!
I have the same error when using mysql. Setting up the schema_migrations table manually with like this does not help.
CREATE TABLE `schema_migrations` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`version` text NOT NULL,
`migrated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
create model for it also
发自我的 iPhone
在 2015年1月17日,18:42,Peter Krantz [email protected] 写道:
I have the same error when using mysql. Setting up the schema_migrations table manually with like this does not help.
CREATE TABLE
schema_migrations
(id
int(11) unsigned NOT NULL AUTO_INCREMENT,version
text NOT NULL,migrated_at
datetime DEFAULT NULL, PRIMARY KEY (id
) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; — Reply to this email directly or view it on GitHub.
A model is not necessary
Indeed, you should not create a model for that table.
Someone is going to need to hack on the Mysql adapter and fix things up if it is not currently functional. The Postgres adapter is the one I originally added transactions to, so it's the one to use as a model.
Or, you could always just use Postgres :-)
It is already fixed in aforementioned #205.