Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boss_migrate cannot handle "schema_migrations"? #198

Open
liuzhen opened this issue Oct 15, 2014 · 23 comments · May be fixed by #205
Open

boss_migrate cannot handle "schema_migrations"? #198

liuzhen opened this issue Oct 15, 2014 · 23 comments · May be fixed by #205

Comments

@liuzhen
Copy link

liuzhen commented Oct 15, 2014

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}]}]},

@liuzhen
Copy link
Author

liuzhen commented Oct 21, 2014

After I went for pgsql, everything works.

@liuzhen liuzhen closed this as completed Oct 21, 2014
@rredpoppy
Copy link

Why is this issue closed? This is not a fix for the MySql adapter.

@davidw
Copy link
Contributor

davidw commented Nov 18, 2014

@adrianrosian is it something you are able to test?

@rredpoppy
Copy link

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

@davidw davidw reopened this Nov 18, 2014
@liuzhen
Copy link
Author

liuzhen commented Nov 19, 2014

Sorry. By the way, the create_table/2 in adapter for pgsql only works with least expectations.

@davidw
Copy link
Contributor

davidw commented Nov 19, 2014

What do you mean by 'least expectations'?

@liuzhen
Copy link
Author

liuzhen commented Nov 20, 2014

@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.

@davidw
Copy link
Contributor

davidw commented Nov 20, 2014

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.

@liuzhen
Copy link
Author

liuzhen commented Nov 21, 2014

@davidw I saw that. Thank you.

@skalee skalee linked a pull request Nov 21, 2014 that will close this issue
@skalee
Copy link

skalee commented Nov 21, 2014

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).

@Bunlong
Copy link

Bunlong commented Jan 8, 2015

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!

@davidw
Copy link
Contributor

davidw commented Jan 8, 2015

boss_db_adapter_mock

Offhand, that doesn't look like Mysql...

@Bunlong
Copy link

Bunlong commented Jan 8, 2015

@davidw: So how can I fix it Sir?

@davidw
Copy link
Contributor

davidw commented Jan 8, 2015

You should probably configure CB to use Mysql. Or, even better, use Postgres :-)

@Bunlong
Copy link

Bunlong commented Jan 9, 2015

@davidw: Yes I've already configured CB to use Mysql. I can connect to Mysql but I can't run migrate. :(

@liuzhen
Copy link
Author

liuzhen commented Jan 9, 2015

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.

@liuzhen
Copy link
Author

liuzhen commented Jan 9, 2015

@Bunlong
"schema_migrations": id, version (varchar), migrated_at (like timestamp).

@Bunlong
Copy link

Bunlong commented Jan 9, 2015

@liuzhen: I am a newbie with Chicagoboss, Could you details more than this? Thank you!

@peterk
Copy link

peterk commented Jan 17, 2015

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;

@liuzhen
Copy link
Author

liuzhen commented Jan 17, 2015

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.

@davidw
Copy link
Contributor

davidw commented Jan 17, 2015

A model is not necessary

@davidw
Copy link
Contributor

davidw commented Jan 17, 2015

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 :-)

@skalee
Copy link

skalee commented Jan 19, 2015

It is already fixed in aforementioned #205.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants