/* WIP Under Construction */ package main import ( "fmt" "log" "os" "runtime/debug" "./lib" ) // TODO: Make sure all the errors in this file propagate upwards properly func main() { // Capture panics instead of closing the window at a superhuman speed before the user can read the message on Windows defer func() { r := recover() if r != nil { fmt.Println(r) debug.PrintStack() return } }() log.Println("Running the query generator") for _, adapter := range qgen.Registry { log.Printf("Building the queries for the %s adapter", adapter.GetName()) qgen.Install.SetAdapterInstance(adapter) qgen.Install.AddPlugins(NewPrimaryKeySpitter()) // TODO: Do we really need to fill the spitter for every adapter? err := writeStatements(adapter) if err != nil { log.Print(err) } err = qgen.Install.Write() if err != nil { log.Print(err) } err = adapter.Write() if err != nil { log.Print(err) } } } // nolint func writeStatements(adapter qgen.Adapter) error { err := createTables(adapter) if err != nil { return err } err = seedTables(adapter) if err != nil { return err } err = writeSelects(adapter) if err != nil { return err } err = writeLeftJoins(adapter) if err != nil { return err } err = writeInnerJoins(adapter) if err != nil { return err } err = writeInserts(adapter) if err != nil { return err } err = writeUpdates(adapter) if err != nil { return err } err = writeDeletes(adapter) if err != nil { return err } err = writeSimpleCounts(adapter) if err != nil { return err } err = writeInsertSelects(adapter) if err != nil { return err } err = writeInsertLeftJoins(adapter) if err != nil { return err } err = writeInsertInnerJoins(adapter) if err != nil { return err } return nil } func seedTables(adapter qgen.Adapter) error { qgen.Install.SimpleInsert("sync", "last_update", "UTC_TIMESTAMP()") qgen.Install.SimpleInsert("settings", "name, content, type", "'url_tags','1','bool'") qgen.Install.SimpleInsert("settings", "name, content, type, constraints", "'activation_type','1','list','1-3'") qgen.Install.SimpleInsert("settings", "name, content, type", "'bigpost_min_words','250','int'") qgen.Install.SimpleInsert("settings", "name, content, type", "'megapost_min_words','1000','int'") qgen.Install.SimpleInsert("settings", "name, content, type", "'meta_desc','','html-attribute'") qgen.Install.SimpleInsert("themes", "uname, default", "'cosora',1") qgen.Install.SimpleInsert("emails", "email, uid, validated", "'admin@localhost',1,1") // ? - Use a different default email or let the admin input it during installation? /* The Permissions: Global Permissions: BanUsers ActivateUsers EditUser EditUserEmail EditUserPassword EditUserGroup EditUserGroupSuperMod EditUserGroupAdmin EditGroup EditGroupLocalPerms EditGroupGlobalPerms EditGroupSuperMod EditGroupAdmin ManageForums EditSettings ManageThemes ManagePlugins ViewAdminLogs ViewIPs Non-staff Global Permissions: UploadFiles Forum Permissions: ViewTopic LikeItem CreateTopic EditTopic DeleteTopic CreateReply EditReply DeleteReply PinTopic CloseTopic MoveTopic */ // TODO: Set the permissions on a struct and then serialize the struct and insert that instead of writing raw JSON qgen.Install.SimpleInsert("users_groups", "name, permissions, plugin_perms, is_mod, is_admin, tag", `'Administrator','{"BanUsers":true,"ActivateUsers":true,"EditUser":true,"EditUserEmail":true,"EditUserPassword":true,"EditUserGroup":true,"EditUserGroupSuperMod":true,"EditUserGroupAdmin":false,"EditGroup":true,"EditGroupLocalPerms":true,"EditGroupGlobalPerms":true,"EditGroupSuperMod":true,"EditGroupAdmin":false,"ManageForums":true,"EditSettings":true,"ManageThemes":true,"ManagePlugins":true,"ViewAdminLogs":true,"ViewIPs":true,"UploadFiles":true,"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"EditTopic":true,"DeleteTopic":true,"CreateReply":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true,"MoveTopic":true}','{}',1,1,"Admin"`) qgen.Install.SimpleInsert("users_groups", "name, permissions, plugin_perms, is_mod, tag", `'Moderator','{"BanUsers":true,"ActivateUsers":false,"EditUser":true,"EditUserEmail":false,"EditUserGroup":true,"ViewIPs":true,"UploadFiles":true,"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"EditTopic":true,"DeleteTopic":true,"CreateReply":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true,"MoveTopic":true}','{}',1,"Mod"`) qgen.Install.SimpleInsert("users_groups", "name, permissions, plugin_perms", `'Member','{"UploadFiles":true,"ViewTopic":true,"LikeItem":true,"CreateTopic":true,"CreateReply":true}','{}'`) qgen.Install.SimpleInsert("users_groups", "name, permissions, plugin_perms, is_banned", `'Banned','{"ViewTopic":true}','{}',1`) qgen.Install.SimpleInsert("users_groups", "name, permissions, plugin_perms", `'Awaiting Activation','{"ViewTopic":true}','{}'`) qgen.Install.SimpleInsert("users_groups", "name, permissions, plugin_perms, tag", `'Not Loggedin','{"ViewTopic":true}','{}','Guest'`) // // TODO: Stop processFields() from stripping the spaces in the descriptions in the next commit qgen.Install.SimpleInsert("forums", "name, active, desc", "'Reports',0,'All the reports go here'") qgen.Install.SimpleInsert("forums", "name, lastTopicID, lastReplyerID, desc", "'General',1,1,'A place for general discussions which don't fit elsewhere'") // qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", `1,1,'{"ViewTopic":true,"CreateReply":true,"CreateTopic":true,"PinTopic":true,"CloseTopic":true}'`) qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", `2,1,'{"ViewTopic":true,"CreateReply":true,"CloseTopic":true}'`) qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", "3,1,'{}'") qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", "4,1,'{}'") qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", "5,1,'{}'") qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", "6,1,'{}'") // qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", `1,2,'{"ViewTopic":true,"CreateReply":true,"CreateTopic":true,"LikeItem":true,"EditTopic":true,"DeleteTopic":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true,"MoveTopic":true}'`) qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", `2,2,'{"ViewTopic":true,"CreateReply":true,"CreateTopic":true,"LikeItem":true,"EditTopic":true,"DeleteTopic":true,"EditReply":true,"DeleteReply":true,"PinTopic":true,"CloseTopic":true,"MoveTopic":true}'`) qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", `3,2,'{"ViewTopic":true,"CreateReply":true,"CreateTopic":true,"LikeItem":true}'`) qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", `4,2,'{"ViewTopic":true}'`) qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", `5,2,'{"ViewTopic":true}'`) qgen.Install.SimpleInsert("forums_permissions", "gid, fid, permissions", `6,2,'{"ViewTopic":true}'`) // qgen.Install.SimpleInsert("topics", "title, content, parsed_content, createdAt, lastReplyAt, lastReplyBy, createdBy, parentID, ipaddress", "'Test Topic','A topic automatically generated by the software.','A topic automatically generated by the software.',UTC_TIMESTAMP(),UTC_TIMESTAMP(),1,1,2,'::1'") qgen.Install.SimpleInsert("replies", "tid, content, parsed_content, createdAt, createdBy, lastUpdated, lastEdit, lastEditBy, ipaddress", "1,'A reply!','A reply!',UTC_TIMESTAMP(),1,UTC_TIMESTAMP(),0,0,'::1'") /* {{range .MenuItems}}