From 830cac6e18c752574685e37d79079bc67e9606c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ska=C5=82acki?= Date: Fri, 21 Nov 2014 17:59:37 +0100 Subject: [PATCH 1/2] Table_exists: expect table name, not model name 1. Make API compatible with PostgreSQL adapter 2. Make it working when called with schema_migrations 3. It generally makes more sense to work with SQL table names, models can be renamed or deleted which would break old migrations. --- src/db_adapters/boss_db_adapter_mysql.erl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/db_adapters/boss_db_adapter_mysql.erl b/src/db_adapters/boss_db_adapter_mysql.erl index e1fe7cf0..62eba8a5 100644 --- a/src/db_adapters/boss_db_adapter_mysql.erl +++ b/src/db_adapters/boss_db_adapter_mysql.erl @@ -100,10 +100,9 @@ count(Pid, Type, Conditions) -> {error, MysqlRes} -> {error, mysql:get_result_reason(MysqlRes)} end. - -table_exists(Pid, Type) -> - TableName = boss_record_lib:database_table(Type), - Res = fetch(Pid, ["SELECT 1 FROM ", TableName," LIMIT 1"]), + +table_exists(Pid, TableName) when is_atom(TableName) -> + Res = fetch(Pid, ["SELECT 1 FROM ", atom_to_list(TableName)," LIMIT 1"]), case Res of {updated, _} -> ok; From c07e94bc1a471540d8e9f9390baf4ea9990f5f72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Ska=C5=82acki?= Date: Fri, 21 Nov 2014 19:22:20 +0100 Subject: [PATCH 2/2] MySQL adapter: Fix pattern in table_exists This is SELECT query, so MySQL will rather return {data,{mysql_result, ...}} tuple. --- src/db_adapters/boss_db_adapter_mysql.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/db_adapters/boss_db_adapter_mysql.erl b/src/db_adapters/boss_db_adapter_mysql.erl index 62eba8a5..ba8446e9 100644 --- a/src/db_adapters/boss_db_adapter_mysql.erl +++ b/src/db_adapters/boss_db_adapter_mysql.erl @@ -104,8 +104,8 @@ count(Pid, Type, Conditions) -> table_exists(Pid, TableName) when is_atom(TableName) -> Res = fetch(Pid, ["SELECT 1 FROM ", atom_to_list(TableName)," LIMIT 1"]), case Res of - {updated, _} -> - ok; + {data, _} -> + true; {error, MysqlRes} -> {error, mysql:get_result_reason(MysqlRes)} end.