diff --git a/calexium_lib b/calexium_lib index eba0f76..ec6480d 160000 --- a/calexium_lib +++ b/calexium_lib @@ -1 +1 @@ -Subproject commit eba0f762de01ad8cd7c4aa41ea78c9f641d74e03 +Subproject commit ec6480d924ed1291d9c5017b8f878104544ae1a6 diff --git a/hayamiki.aproj b/hayamiki.aproj index 367b289..b70c937 100644 --- a/hayamiki.aproj +++ b/hayamiki.aproj @@ -472,6 +472,7 @@ + diff --git a/src/check.anubis b/src/check.anubis index 2f4db93..8f0550a 100644 --- a/src/check.anubis +++ b/src/check.anubis @@ -42,7 +42,7 @@ define Maybe(HK_Model_Column) )= since col is hk_column(name, type, attrib, help), if type is foreign_key(fk_app, fk_table) then - with mb_fk_app = if (fk_app) is + with mb_fk_app = if (fk_app) is { this then println("this found replaced by "+current_app_name+" in app '"+current_app_name+"' table '"+table_name+"' column '"+name+"'"); success(current_app_name), @@ -145,7 +145,8 @@ public define Maybe(HK_Database) if get_all_apps_name(apps, []) is { failure then failure, - success(chk_apps) then + success(chk_apps) then + //TODO Check for reserved keyword used in column name, table name if resolve_foreign(chk_apps, apps, []) is { failure then failure, diff --git a/src/generation/create_table.anubis b/src/generation/create_table.anubis index 4a882ca..7ae2a3d 100644 --- a/src/generation/create_table.anubis +++ b/src/generation/create_table.anubis @@ -11,6 +11,7 @@ read calexium_lib/database/model/db_model.anubis read tools/basis.anubis read tools/int.anubis read system/string.anubis +read system/files.anubis read tools/streams.anubis read tools/ISO-8601.anubis @@ -30,6 +31,7 @@ define String List(HK_Model_Column) columns, String indent )= + //get the longest column name size, to be able to make formatting according to column name. with column_max_size = max(columns), join(",\n"+indent, map((HK_Model_Column column) |-> create_table_generate_one_column(column, column_max_size+1), columns)) . @@ -60,16 +62,18 @@ define String )= if tables is { - [] then + [] then //no more table to generate if apps is { - [] then so_far, - [app. t_apps] then + [] then //no more apps to generate + so_far, //return the all create table generated so far + [app. t_apps] then //another app available since app is hk_app(name, app_tables), create_table_generate_all_tables(t_apps, app_tables, so_far + "\n /************ TABLES for Application '"+name+"' ***************/") }, [table . t] then + //generate the current table "CREATE TABLE" create_table_generate_all_tables(apps, t, so_far + create_table_generate_one_table(table)) }. @@ -92,13 +96,15 @@ define String generate_all_tables_list ( List(HK_App) apps, - List(HK_Table) tables, //list of the table model description +// List(HK_Table) tables, //list of the table model description String indent )= //calculate then longest table name and add 4 for enclosed quote + coma + final space //hence we can make a beautiful formatting with max_space = longest_table_name_size(apps, 0) + 4, - join(",\n",map((HK_Table table) |-> indent+"table("+fill("\""+table.name+"\",", max_space)+"create_table_"+table.name+")", tables)). + join(",\n", + map_append((HK_App app) |-> since app is hk_app(_, tables), + map((HK_Table table) |-> indent+"table("+fill("\""+table.name+"\",", max_space)+"create_table_"+table.name+")", tables), apps)). public define Maybe(One) generate_create_table @@ -106,33 +112,39 @@ public define Maybe(One) List(HK_App) apps //list of the table model description )= //TODO manage version - with version = "1.0.0", + with version = "1.0.0.0", version_str = find_and_replace(version,".","_"), //replace the dot by underscore because dot is not allowed in function name by Anubis language - with file_name = "to_"+version+".anubis", - with script_file_name = "to_"+version+"_script.anubis", + with file_name = "database/generated/migration/to_"+version+".anubis", + with script_file_name = "database/generated/migration/to_"+version+"_scripts.anubis", + + //create all necessary directories if doesn't exist. + make_directories(file_name); - //create script file name + //create script file name as new file. Previous file with same name will be erased if file(script_file_name, new) is { - failure then println("Can't create script "+script_file_name);failure, - success(fd_script) then + failure then println("Can't create script "+script_file_name);failure, + success(fd_script) then with script_stream = make_stream(fd_script), //write into script file the generated create table if write_string(script_stream, "/* * Created by 早見木 (Hayamiki). - * User: Automat + * User: Automaton * Date: "+_Int_to_ISO_8601_date(now)+" * Time: "+_Int_to_ISO_8601_time(now)+" * */ -read data_base/alter_table.anubis +read data_base/sqlite_foreign_key.anubis read data_base/db_types.anubis\n"+ //call the generation of all tables create_table_generate_all_tables(apps, [], "")+ //TODO make indexes - "\npublic define List(String) db_indexes = [].\n" + "\npublic define List(String) db_indexes = [].\n"+ + "// ///////////////////////////////\n"+ + "// Foreign keys \n"+ + "public define List((String, String, String, String, FK_Null, FK_Cascade)) db_relations = [].\n" ) is { failure then println ("Can't generate script "+script_file_name);failure, @@ -146,7 +158,7 @@ read data_base/db_types.anubis\n"+ write_string(stream, "/* * Created by 早見木 (Hayamiki). - * User: Automat + * User: Automaton * Date: "+_Int_to_ISO_8601_date(now)+" * Time: "+_Int_to_ISO_8601_time(now)+" * @@ -166,7 +178,7 @@ read types/app_types.anubis read app/app_constants.anubis read app/app_loggers.anubis -read database/generated/migration/to_"+version_str+"_scripts.anubis +read database/generated/migration/to_"+version+"_scripts.anubis define String _version = \""+version+"\". @@ -179,7 +191,7 @@ public define Maybe(One) if drop_all_triggers(db, logger_debug) is failure then failure else with tables = (List(DbTable)) [ -"+generate_all_tables_list(apps, [], " ")+" +"+generate_all_tables_list(apps, " ")+" ], if create_tables(db, logger_debug, tables, _version) is { diff --git a/src/generation/files.anubis b/src/generation/files.anubis index 3b88c10..f17ab91 100644 --- a/src/generation/files.anubis +++ b/src/generation/files.anubis @@ -7,6 +7,7 @@ */ read system/string.anubis +read system/files.anubis read calexium_lib/database/model/db_model.anubis read tools/basis.anubis @@ -30,7 +31,11 @@ define Maybe(One) with model = hk_model([hk_column("id", p_key, []). columns], show_string ), with table = hk_table(name, model, display), println("Generating file for table ["+name+"]"); - with file_name = name+".anubis", + with file_name = "database/generated/"+name+".anubis", + + //create all necessary directories if doesn't exist. + make_directories(file_name); + if file(file_name, new) is { failure then println("can't create file "+file_name);failure, @@ -86,15 +91,15 @@ define Maybe(One) List(String) edit, List(String) writer )= - with file_name = "vtm.anubis", + with file_name = "database/generated/vtm.anubis", if file(file_name, new) is { failure then println("can't create file "+file_name);failure, success(fd) then if write_string(make_stream(fd), "/* - * Created by model_manager. - * User: Automat + * Created by 早見木 (Hayamiki). + * User: Automaton * Date: "+_Int_to_ISO_8601_date(now)+" * Time: "+_Int_to_ISO_8601_time(now)+" * diff --git a/src/model.3.0.0.anubis b/src/model.3.0.0.anubis index 0534c8b..3bbe015 100644 --- a/src/model.3.0.0.anubis +++ b/src/model.3.0.0.anubis @@ -103,9 +103,8 @@ public define HK_Table production_macaddress_table = hk_model( [ - hk_column("mac", char_field(20), []), - hk_column("index", integer_field, []), - hk_column("mailfountain_id", integer_field, []), + hk_column("mac", char_field(20), []), + hk_column("mailfountain_id", integer_field, []), ], "obj.mac+\" = MailFountain[\"+obj.mailfountain_id+\"]\"" ), @@ -709,10 +708,6 @@ public define HK_Database [ //domain manager //mf_serial_table - hk_app("base", - [ - settings_table, - ]), hk_app("production", [ production_mass_storage_table, @@ -743,6 +738,7 @@ public define HK_Database ]), hk_app("", [ + settings_table, django_admin_log_table, address_book_contact_table ]) -- libgit2 0.21.4