2017-10-16 07:32:58 +00:00
package main
2019-10-07 21:22:33 +00:00
import qgen "github.com/Azareal/Gosora/query_gen"
2017-10-16 07:32:58 +00:00
2018-12-27 05:42:41 +00:00
var mysqlPre = "utf8mb4"
var mysqlCol = "utf8mb4_general_ci"
type tblColumn = qgen . DBTableColumn
2019-07-26 23:18:32 +00:00
type tC = tblColumn
2018-12-27 05:42:41 +00:00
type tblKey = qgen . DBTableKey
2019-10-06 22:20:37 +00:00
func createTables ( adapter qgen . Adapter ) ( err error ) {
2019-10-11 00:57:33 +00:00
createTable := func ( table string , charset string , collation string , columns [ ] tC , keys [ ] tblKey ) {
2019-10-06 22:20:37 +00:00
if err != nil {
return
}
err = qgen . Install . CreateTable ( table , charset , collation , columns , keys )
}
createTable ( "users" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "uid" , "int" , 0 , false , true , "" } ,
tC { "name" , "varchar" , 100 , false , false , "" } ,
tC { "password" , "varchar" , 100 , false , false , "" } ,
tC { "salt" , "varchar" , 80 , false , false , "''" } ,
tC { "group" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "active" , "boolean" , 0 , false , false , "0" } ,
tC { "is_super_admin" , "boolean" , 0 , false , false , "0" } ,
tC { "createdAt" , "createdAt" , 0 , false , false , "" } ,
tC { "lastActiveAt" , "datetime" , 0 , false , false , "" } ,
tC { "session" , "varchar" , 200 , false , false , "''" } ,
//tC{"authToken", "varchar", 200, false, false, "''"},
tC { "last_ip" , "varchar" , 200 , false , false , "0.0.0.0.0" } ,
tC { "email" , "varchar" , 200 , false , false , "''" } ,
tC { "avatar" , "varchar" , 100 , false , false , "''" } ,
tC { "message" , "text" , 0 , false , false , "''" } ,
tC { "url_prefix" , "varchar" , 20 , false , false , "''" } ,
tC { "url_name" , "varchar" , 100 , false , false , "''" } ,
tC { "level" , "smallint" , 0 , false , false , "0" } ,
tC { "score" , "int" , 0 , false , false , "0" } ,
tC { "posts" , "int" , 0 , false , false , "0" } ,
tC { "bigposts" , "int" , 0 , false , false , "0" } ,
tC { "megaposts" , "int" , 0 , false , false , "0" } ,
tC { "topics" , "int" , 0 , false , false , "0" } ,
tC { "liked" , "int" , 0 , false , false , "0" } ,
2018-03-31 05:25:27 +00:00
// These two are to bound liked queries with little bits of information we know about the user to reduce the server load
2019-07-26 23:18:32 +00:00
tC { "oldestItemLikedCreatedAt" , "datetime" , 0 , false , false , "" } , // For internal use only, semantics may change
tC { "lastLiked" , "datetime" , 0 , false , false , "" } , // For internal use only, semantics may change
2018-03-31 05:25:27 +00:00
2019-07-26 23:18:32 +00:00
//tC{"penalty_count","int",0,false,false,"0"},
tC { "temp_group" , "int" , 0 , false , false , "0" } , // For temporary groups, set this to zero when a temporary group isn't in effect
2017-11-12 05:25:04 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "uid" , "primary" , "" , false } ,
tblKey { "name" , "unique" , "" , false } ,
2017-10-16 07:32:58 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "users_groups" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "gid" , "int" , 0 , false , true , "" } ,
tC { "name" , "varchar" , 100 , false , false , "" } ,
tC { "permissions" , "text" , 0 , false , false , "" } ,
tC { "plugin_perms" , "text" , 0 , false , false , "" } ,
tC { "is_mod" , "boolean" , 0 , false , false , "0" } ,
tC { "is_admin" , "boolean" , 0 , false , false , "0" } ,
tC { "is_banned" , "boolean" , 0 , false , false , "0" } ,
tC { "user_count" , "int" , 0 , false , false , "0" } , // TODO: Implement this
tC { "tag" , "varchar" , 50 , false , false , "''" } ,
2017-11-12 05:25:04 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "gid" , "primary" , "" , false } ,
2017-10-16 07:32:58 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "users_groups_promotions" , mysqlPre , mysqlCol ,
2019-09-29 04:56:39 +00:00
[ ] tC {
tC { "pid" , "int" , 0 , false , true , "" } ,
tC { "from_gid" , "int" , 0 , false , false , "" } ,
tC { "to_gid" , "int" , 0 , false , false , "" } ,
2019-10-07 21:22:33 +00:00
tC { "two_way" , "boolean" , 0 , false , false , "0" } , // If a user no longer meets the requirements for this promotion then they will be demoted if this flag is set
2019-09-29 04:56:39 +00:00
// Requirements
tC { "level" , "int" , 0 , false , false , "" } ,
2019-10-06 22:20:37 +00:00
tC { "posts" , "int" , 0 , false , false , "0" } ,
2019-09-29 04:56:39 +00:00
tC { "minTime" , "int" , 0 , false , false , "" } , // How long someone needs to have been in their current group before being promoted
} ,
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "pid" , "primary" , "" , false } ,
2019-09-29 04:56:39 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "users_2fa_keys" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "uid" , "int" , 0 , false , false , "" } ,
tC { "secret" , "varchar" , 100 , false , false , "" } ,
tC { "scratch1" , "varchar" , 50 , false , false , "" } ,
tC { "scratch2" , "varchar" , 50 , false , false , "" } ,
tC { "scratch3" , "varchar" , 50 , false , false , "" } ,
tC { "scratch4" , "varchar" , 50 , false , false , "" } ,
tC { "scratch5" , "varchar" , 50 , false , false , "" } ,
tC { "scratch6" , "varchar" , 50 , false , false , "" } ,
tC { "scratch7" , "varchar" , 50 , false , false , "" } ,
tC { "scratch8" , "varchar" , 50 , false , false , "" } ,
tC { "createdAt" , "createdAt" , 0 , false , false , "" } ,
2018-06-17 07:28:18 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "uid" , "primary" , "" , false } ,
2018-06-17 07:28:18 +00:00
} ,
)
2018-06-06 00:21:22 +00:00
2017-10-16 07:32:58 +00:00
// What should we do about global penalties? Put them on the users table for speed? Or keep them here?
// Should we add IP Penalties? No, that's a stupid idea, just implement IP Bans properly. What about shadowbans?
// TODO: Perm overrides
// TODO: Add a mod-queue and other basic auto-mod features. This is needed for awaiting activation and the mod_queue penalty flag
2017-11-02 04:12:51 +00:00
// TODO: Add a penalty type where a user is stopped from creating plugin_guilds social groups
2017-10-16 07:32:58 +00:00
// TODO: Shadow bans. We will probably have a CanShadowBan permission for this, as we *really* don't want people using this lightly.
2019-10-06 22:20:37 +00:00
/ * createTable ( "users_penalties" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "uid" , "int" , 0 , false , false , "" } ,
tC { "element_id" , "int" , 0 , false , false , "" } ,
tC { "element_type" , "varchar" , 50 , false , false , "" } , //forum, profile?, and social_group. Leave blank for global.
tC { "overrides" , "text" , 0 , false , false , "{}" } ,
2017-10-16 07:32:58 +00:00
2019-07-26 23:18:32 +00:00
tC { "mod_queue" , "boolean" , 0 , false , false , "0" } ,
tC { "shadow_ban" , "boolean" , 0 , false , false , "0" } ,
tC { "no_avatar" , "boolean" , 0 , false , false , "0" } , // Coming Soon. Should this be a perm override instead?
2017-10-16 07:32:58 +00:00
// Do we *really* need rate-limit penalty types? Are we going to be allowing bots or something?
2019-07-26 23:18:32 +00:00
//tC{"posts_per_hour","int",0,false,false,"0"},
//tC{"topics_per_hour","int",0,false,false,"0"},
//tC{"posts_count","int",0,false,false,"0"},
//tC{"topic_count","int",0,false,false,"0"},
//tC{"last_hour","int",0,false,false,"0"}, // UNIX Time, as we don't need to do anything too fancy here. When an hour has elapsed since that time, reset the hourly penalty counters.
tC { "issued_by" , "int" , 0 , false , false , "" } ,
tC { "issued_at" , "createdAt" , 0 , false , false , "" } ,
tC { "expires_at" , "datetime" , 0 , false , false , "" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2017-10-16 07:32:58 +00:00
) * /
2019-10-06 22:20:37 +00:00
createTable ( "users_groups_scheduler" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "uid" , "int" , 0 , false , false , "" } ,
tC { "set_group" , "int" , 0 , false , false , "" } ,
2017-10-16 07:32:58 +00:00
2019-07-26 23:18:32 +00:00
tC { "issued_by" , "int" , 0 , false , false , "" } ,
tC { "issued_at" , "createdAt" , 0 , false , false , "" } ,
tC { "revert_at" , "datetime" , 0 , false , false , "" } ,
tC { "temporary" , "boolean" , 0 , false , false , "" } , // special case for permanent bans to do the necessary bookkeeping, might be removed in the future
2017-10-16 07:32:58 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "uid" , "primary" , "" , false } ,
2017-10-16 07:32:58 +00:00
} ,
)
2018-07-28 12:52:23 +00:00
// TODO: Can we use a piece of software dedicated to persistent queues for this rather than relying on the database for it?
2019-10-06 22:20:37 +00:00
createTable ( "users_avatar_queue" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "uid" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
2018-07-28 12:52:23 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "uid" , "primary" , "" , false } ,
2018-07-28 12:52:23 +00:00
} ,
)
// TODO: Should we add a users prefix to this table to fit the "unofficial convention"?
2019-11-10 02:37:53 +00:00
// TODO: Add an autoincrement key?
2019-10-06 22:20:37 +00:00
createTable ( "emails" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "email" , "varchar" , 200 , false , false , "" } ,
tC { "uid" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "validated" , "boolean" , 0 , false , false , "0" } ,
tC { "token" , "varchar" , 200 , false , false , "''" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2017-10-16 07:32:58 +00:00
)
2018-07-05 09:54:01 +00:00
// TODO: Allow for patterns in domains, if the bots try to shake things up there?
/ *
2019-10-06 22:20:37 +00:00
createTable ( "email_domain_blacklist" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "domain" , "varchar" , 200 , false , false , "" } ,
tC { "gtld" , "boolean" , 0 , false , false , "0" } ,
2018-07-05 09:54:01 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
tblKey { "domain" , "primary" } ,
2018-07-05 09:54:01 +00:00
} ,
)
* /
2019-01-21 12:27:59 +00:00
// TODO: Implement password resets
2019-10-06 22:20:37 +00:00
createTable ( "password_resets" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "email" , "varchar" , 200 , false , false , "" } ,
tC { "uid" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "validated" , "varchar" , 200 , false , false , "" } , // Token given once the one-use token is consumed, used to prevent multiple people consuming the same one-use token
tC { "token" , "varchar" , 200 , false , false , "" } ,
tC { "createdAt" , "createdAt" , 0 , false , false , "" } ,
2019-03-11 08:47:45 +00:00
} , nil ,
)
2019-01-21 12:27:59 +00:00
2019-10-06 22:20:37 +00:00
createTable ( "forums" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "fid" , "int" , 0 , false , true , "" } ,
tC { "name" , "varchar" , 100 , false , false , "" } ,
tC { "desc" , "varchar" , 200 , false , false , "" } ,
tC { "tmpl" , "varchar" , 200 , false , false , "''" } ,
tC { "active" , "boolean" , 0 , false , false , "1" } ,
tC { "order" , "int" , 0 , false , false , "0" } ,
tC { "topicCount" , "int" , 0 , false , false , "0" } ,
tC { "preset" , "varchar" , 100 , false , false , "''" } ,
tC { "parentID" , "int" , 0 , false , false , "0" } ,
tC { "parentType" , "varchar" , 50 , false , false , "''" } ,
tC { "lastTopicID" , "int" , 0 , false , false , "0" } ,
tC { "lastReplyerID" , "int" , 0 , false , false , "0" } ,
2017-11-12 05:25:04 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "fid" , "primary" , "" , false } ,
2017-10-16 07:32:58 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "forums_permissions" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "fid" , "int" , 0 , false , false , "" } ,
tC { "gid" , "int" , 0 , false , false , "" } ,
tC { "preset" , "varchar" , 100 , false , false , "''" } ,
tC { "permissions" , "text" , 0 , false , false , "" } ,
2017-10-16 07:32:58 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2017-10-16 07:32:58 +00:00
// TODO: Test to see that the compound primary key works
2019-10-07 21:22:33 +00:00
tblKey { "fid,gid" , "primary" , "" , false } ,
2018-12-27 05:42:41 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "topics" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "tid" , "int" , 0 , false , true , "" } ,
tC { "title" , "varchar" , 100 , false , false , "" } , // TODO: Increase the max length to 200?
tC { "content" , "text" , 0 , false , false , "" } ,
tC { "parsed_content" , "text" , 0 , false , false , "" } ,
tC { "createdAt" , "createdAt" , 0 , false , false , "" } ,
tC { "lastReplyAt" , "datetime" , 0 , false , false , "" } ,
tC { "lastReplyBy" , "int" , 0 , false , false , "" } ,
tC { "lastReplyID" , "int" , 0 , false , false , "0" } ,
tC { "createdBy" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "is_closed" , "boolean" , 0 , false , false , "0" } ,
tC { "sticky" , "boolean" , 0 , false , false , "0" } ,
2018-10-06 13:14:11 +00:00
// TODO: Add an index for this
2019-07-26 23:18:32 +00:00
tC { "parentID" , "int" , 0 , false , false , "2" } ,
tC { "ipaddress" , "varchar" , 200 , false , false , "0.0.0.0.0" } ,
tC { "postCount" , "int" , 0 , false , false , "1" } ,
tC { "likeCount" , "int" , 0 , false , false , "0" } ,
tC { "attachCount" , "int" , 0 , false , false , "0" } ,
tC { "words" , "int" , 0 , false , false , "0" } ,
tC { "views" , "int" , 0 , false , false , "0" } ,
//tC{"dailyViews", "int", 0, false, false, "0"},
//tC{"weeklyViews", "int", 0, false, false, "0"},
//tC{"monthlyViews", "int", 0, false, false, "0"},
2018-10-06 13:14:11 +00:00
// ? - A little hacky, maybe we could do something less likely to bite us with huge numbers of topics?
// TODO: Add an index for this?
2019-07-26 23:18:32 +00:00
//tC{"lastMonth", "datetime", 0, false, false, ""},
tC { "css_class" , "varchar" , 100 , false , false , "''" } ,
tC { "poll" , "int" , 0 , false , false , "0" } ,
tC { "data" , "varchar" , 200 , false , false , "''" } ,
2018-12-27 05:42:41 +00:00
} ,
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "tid" , "primary" , "" , false } ,
tblKey { "content" , "fulltext" , "" , false } ,
2018-12-27 05:42:41 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "replies" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "rid" , "int" , 0 , false , true , "" } , // TODO: Rename to replyID?
tC { "tid" , "int" , 0 , false , false , "" } , // TODO: Rename to topicID?
tC { "content" , "text" , 0 , false , false , "" } ,
tC { "parsed_content" , "text" , 0 , false , false , "" } ,
tC { "createdAt" , "createdAt" , 0 , false , false , "" } ,
tC { "createdBy" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "lastEdit" , "int" , 0 , false , false , "0" } ,
tC { "lastEditBy" , "int" , 0 , false , false , "0" } ,
tC { "lastUpdated" , "datetime" , 0 , false , false , "" } ,
tC { "ipaddress" , "varchar" , 200 , false , false , "0.0.0.0.0" } ,
tC { "likeCount" , "int" , 0 , false , false , "0" } ,
tC { "attachCount" , "int" , 0 , false , false , "0" } ,
tC { "words" , "int" , 0 , false , false , "1" } , // ? - replies has a default of 1 and topics has 0? why?
tC { "actionType" , "varchar" , 20 , false , false , "''" } ,
tC { "poll" , "int" , 0 , false , false , "0" } ,
2018-12-27 05:42:41 +00:00
} ,
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "rid" , "primary" , "" , false } ,
tblKey { "content" , "fulltext" , "" , false } ,
2018-12-27 05:42:41 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "attachments" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "attachID" , "int" , 0 , false , true , "" } ,
tC { "sectionID" , "int" , 0 , false , false , "0" } ,
tC { "sectionTable" , "varchar" , 200 , false , false , "forums" } ,
tC { "originID" , "int" , 0 , false , false , "" } ,
tC { "originTable" , "varchar" , 200 , false , false , "replies" } ,
tC { "uploadedBy" , "int" , 0 , false , false , "" } , // TODO; Make this a foreign key
tC { "path" , "varchar" , 200 , false , false , "" } ,
tC { "extra" , "varchar" , 200 , false , false , "" } ,
2018-12-27 05:42:41 +00:00
} ,
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "attachID" , "primary" , "" , false } ,
2018-12-27 05:42:41 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "revisions" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "reviseID" , "int" , 0 , false , true , "" } ,
tC { "content" , "text" , 0 , false , false , "" } ,
tC { "contentID" , "int" , 0 , false , false , "" } ,
tC { "contentType" , "varchar" , 100 , false , false , "replies" } ,
tC { "createdAt" , "createdAt" , 0 , false , false , "" } ,
2018-03-31 05:25:27 +00:00
// TODO: Add a createdBy column?
2017-10-16 07:32:58 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "reviseID" , "primary" , "" , false } ,
2018-02-10 15:07:21 +00:00
} ,
2017-10-16 07:32:58 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "polls" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "pollID" , "int" , 0 , false , true , "" } ,
tC { "parentID" , "int" , 0 , false , false , "0" } ,
tC { "parentTable" , "varchar" , 100 , false , false , "topics" } , // topics, replies
tC { "type" , "int" , 0 , false , false , "0" } ,
tC { "options" , "json" , 0 , false , false , "" } ,
tC { "votes" , "int" , 0 , false , false , "0" } ,
2018-01-25 04:57:33 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "pollID" , "primary" , "" , false } ,
2018-01-25 04:57:33 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "polls_options" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "pollID" , "int" , 0 , false , false , "" } ,
tC { "option" , "int" , 0 , false , false , "0" } ,
tC { "votes" , "int" , 0 , false , false , "0" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2018-01-28 14:30:24 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "polls_votes" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "pollID" , "int" , 0 , false , false , "" } ,
tC { "uid" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "option" , "int" , 0 , false , false , "0" } ,
tC { "castAt" , "createdAt" , 0 , false , false , "" } ,
tC { "ipaddress" , "varchar" , 200 , false , false , "0.0.0.0.0" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2018-01-25 04:57:33 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "users_replies" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "rid" , "int" , 0 , false , true , "" } ,
tC { "uid" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "content" , "text" , 0 , false , false , "" } ,
tC { "parsed_content" , "text" , 0 , false , false , "" } ,
tC { "createdAt" , "createdAt" , 0 , false , false , "" } ,
tC { "createdBy" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "lastEdit" , "int" , 0 , false , false , "0" } ,
tC { "lastEditBy" , "int" , 0 , false , false , "0" } ,
tC { "ipaddress" , "varchar" , 200 , false , false , "0.0.0.0.0" } ,
2017-11-12 05:25:04 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "rid" , "primary" , "" , false } ,
2017-10-16 07:32:58 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "likes" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "weight" , "tinyint" , 0 , false , false , "1" } ,
tC { "targetItem" , "int" , 0 , false , false , "" } ,
tC { "targetType" , "varchar" , 50 , false , false , "replies" } ,
tC { "sentBy" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "createdAt" , "createdAt" , 0 , false , false , "" } ,
tC { "recalc" , "tinyint" , 0 , false , false , "0" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2017-10-16 07:32:58 +00:00
)
2019-07-26 23:18:32 +00:00
//columns("participants, createdBy, createdAt, lastReplyBy, lastReplyAt").Where("cid = ?")
2019-10-06 22:20:37 +00:00
createTable ( "conversations" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "cid" , "int" , 0 , false , true , "" } ,
tC { "createdBy" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "createdAt" , "createdAt" , 0 , false , false , "" } ,
tC { "lastReplyAt" , "datetime" , 0 , false , false , "" } ,
tC { "lastReplyBy" , "int" , 0 , false , false , "" } ,
} ,
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "cid" , "primary" , "" , false } ,
2019-07-26 23:18:32 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "conversations_posts" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "pid" , "int" , 0 , false , true , "" } ,
tC { "cid" , "int" , 0 , false , false , "" } ,
tC { "createdBy" , "int" , 0 , false , false , "" } ,
tC { "body" , "varchar" , 50 , false , false , "" } ,
tC { "post" , "varchar" , 50 , false , false , "''" } ,
} ,
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "pid" , "primary" , "" , false } ,
2019-07-26 23:18:32 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "conversations_participants" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "uid" , "int" , 0 , false , false , "" } ,
tC { "cid" , "int" , 0 , false , false , "" } ,
} , nil ,
2019-08-14 10:39:04 +00:00
)
2019-07-26 23:18:32 +00:00
2019-10-07 21:22:33 +00:00
/ *
2019-10-11 00:57:33 +00:00
createTable ( "users_friends" , "" , "" ,
[ ] tC {
tC { "uid" , "int" , 0 , false , false , "" } ,
tC { "uid2" , "int" , 0 , false , false , "" } ,
} , nil ,
)
createTable ( "users_friends_invites" , "" , "" ,
[ ] tC {
tC { "requester" , "int" , 0 , false , false , "" } ,
tC { "target" , "int" , 0 , false , false , "" } ,
} , nil ,
)
2019-10-07 21:22:33 +00:00
* /
2019-10-18 00:35:13 +00:00
createTable ( "users_blocks" , "" , "" ,
[ ] tC {
tC { "blocker" , "int" , 0 , false , false , "" } ,
tC { "blockedUser" , "int" , 0 , false , false , "" } ,
} , nil ,
)
2019-10-06 22:20:37 +00:00
createTable ( "activity_stream_matches" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "watcher" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "asid" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
2019-10-07 21:22:33 +00:00
} ,
2019-05-06 04:04:00 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "asid,asid" , "foreign" , "activity_stream" , true } ,
2019-05-06 04:04:00 +00:00
} ,
2017-10-16 07:32:58 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "activity_stream" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "asid" , "int" , 0 , false , true , "" } ,
tC { "actor" , "int" , 0 , false , false , "" } , /* the one doing the act */ // TODO: Make this a foreign key
tC { "targetUser" , "int" , 0 , false , false , "" } , /* the user who created the item the actor is acting on, some items like forums may lack a targetUser field */
tC { "event" , "varchar" , 50 , false , false , "" } , /* mention, like, reply (as in the act of replying to an item, not the reply item type, you can "reply" to a forum by making a topic in it), friend_invite */
tC { "elementType" , "varchar" , 50 , false , false , "" } , /* topic, post (calling it post here to differentiate it from the 'reply' event), forum, user */
tC { "elementID" , "int" , 0 , false , false , "" } , /* the ID of the element being acted upon */
tC { "createdAt" , "createdAt" , 0 , false , false , "" } ,
2017-10-16 07:32:58 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "asid" , "primary" , "" , false } ,
2017-10-16 07:32:58 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "activity_subscriptions" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "user" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "targetID" , "int" , 0 , false , false , "" } , /* the ID of the element being acted upon */
tC { "targetType" , "varchar" , 50 , false , false , "" } , /* topic, post (calling it post here to differentiate it from the 'reply' event), forum, user */
tC { "level" , "int" , 0 , false , false , "0" } , /* 0: Mentions (aka the global default for any post), 1: Replies To You, 2: All Replies*/
2019-01-21 12:27:59 +00:00
} , nil ,
2017-10-16 07:32:58 +00:00
)
/* Due to MySQL's design, we have to drop the unique keys for table settings, plugins, and themes down from 200 to 180 or it will error */
2019-10-06 22:20:37 +00:00
createTable ( "settings" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "name" , "varchar" , 180 , false , false , "" } ,
tC { "content" , "varchar" , 250 , false , false , "" } ,
tC { "type" , "varchar" , 50 , false , false , "" } ,
tC { "constraints" , "varchar" , 200 , false , false , "''" } ,
2017-10-16 07:32:58 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "name" , "unique" , "" , false } ,
2017-10-16 07:32:58 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "word_filters" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "wfid" , "int" , 0 , false , true , "" } ,
tC { "find" , "varchar" , 200 , false , false , "" } ,
tC { "replacement" , "varchar" , 200 , false , false , "" } ,
2017-10-16 07:32:58 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "wfid" , "primary" , "" , false } ,
2017-10-16 07:32:58 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "plugins" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "uname" , "varchar" , 180 , false , false , "" } ,
tC { "active" , "boolean" , 0 , false , false , "0" } ,
tC { "installed" , "boolean" , 0 , false , false , "0" } ,
2017-10-16 07:32:58 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "uname" , "unique" , "" , false } ,
2017-10-16 07:32:58 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "themes" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "uname" , "varchar" , 180 , false , false , "" } ,
tC { "default" , "boolean" , 0 , false , false , "0" } ,
//tC{"profileUserVars", "text", 0, false, false, "''"},
2017-10-16 07:32:58 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "uname" , "unique" , "" , false } ,
2017-10-16 07:32:58 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "widgets" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "wid" , "int" , 0 , false , true , "" } ,
tC { "position" , "int" , 0 , false , false , "" } ,
tC { "side" , "varchar" , 100 , false , false , "" } ,
tC { "type" , "varchar" , 100 , false , false , "" } ,
tC { "active" , "boolean" , 0 , false , false , "0" } ,
tC { "location" , "varchar" , 100 , false , false , "" } ,
tC { "data" , "text" , 0 , false , false , "''" } ,
2017-11-12 05:25:04 +00:00
} ,
2019-01-21 12:27:59 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "wid" , "primary" , "" , false } ,
2019-01-21 12:27:59 +00:00
} ,
2017-10-16 07:32:58 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "menus" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "mid" , "int" , 0 , false , true , "" } ,
2018-04-22 12:33:56 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "mid" , "primary" , "" , false } ,
2018-04-22 12:33:56 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "menu_items" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "miid" , "int" , 0 , false , true , "" } ,
tC { "mid" , "int" , 0 , false , false , "" } ,
tC { "name" , "varchar" , 200 , false , false , "''" } ,
tC { "htmlID" , "varchar" , 200 , false , false , "''" } ,
tC { "cssClass" , "varchar" , 200 , false , false , "''" } ,
tC { "position" , "varchar" , 100 , false , false , "" } ,
tC { "path" , "varchar" , 200 , false , false , "''" } ,
tC { "aria" , "varchar" , 200 , false , false , "''" } ,
tC { "tooltip" , "varchar" , 200 , false , false , "''" } ,
tC { "tmplName" , "varchar" , 200 , false , false , "''" } ,
tC { "order" , "int" , 0 , false , false , "0" } ,
tC { "guestOnly" , "boolean" , 0 , false , false , "0" } ,
tC { "memberOnly" , "boolean" , 0 , false , false , "0" } ,
tC { "staffOnly" , "boolean" , 0 , false , false , "0" } ,
tC { "adminOnly" , "boolean" , 0 , false , false , "0" } ,
2018-12-27 05:42:41 +00:00
} ,
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "miid" , "primary" , "" , false } ,
2018-12-27 05:42:41 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "pages" , mysqlPre , mysqlCol ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "pid" , "int" , 0 , false , true , "" } ,
//tC{"path", "varchar", 200, false, false, ""},
tC { "name" , "varchar" , 200 , false , false , "" } ,
tC { "title" , "varchar" , 200 , false , false , "" } ,
tC { "body" , "text" , 0 , false , false , "" } ,
2018-05-27 09:36:35 +00:00
// TODO: Make this a table?
2019-07-26 23:18:32 +00:00
tC { "allowedGroups" , "text" , 0 , false , false , "" } ,
tC { "menuID" , "int" , 0 , false , false , "-1" } , // simple sidebar menu
2018-05-27 09:36:35 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "pid" , "primary" , "" , false } ,
2018-05-27 09:36:35 +00:00
} ,
)
2019-10-06 22:20:37 +00:00
createTable ( "registration_logs" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "rlid" , "int" , 0 , false , true , "" } ,
tC { "username" , "varchar" , 100 , false , false , "" } ,
tC { "email" , "varchar" , 100 , false , false , "" } ,
tC { "failureReason" , "varchar" , 100 , false , false , "" } ,
tC { "success" , "bool" , 0 , false , false , "0" } , // Did this attempt succeed?
tC { "ipaddress" , "varchar" , 200 , false , false , "" } ,
tC { "doneAt" , "createdAt" , 0 , false , false , "" } ,
2018-05-16 10:46:14 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "rlid" , "primary" , "" , false } ,
2018-05-16 10:46:14 +00:00
} ,
)
2018-04-03 04:34:07 +00:00
2019-10-06 22:20:37 +00:00
createTable ( "login_logs" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "lid" , "int" , 0 , false , true , "" } ,
tC { "uid" , "int" , 0 , false , false , "" } ,
tC { "success" , "bool" , 0 , false , false , "0" } , // Did this attempt succeed?
tC { "ipaddress" , "varchar" , 200 , false , false , "" } ,
tC { "doneAt" , "createdAt" , 0 , false , false , "" } ,
2018-12-17 04:58:55 +00:00
} ,
2018-12-27 05:42:41 +00:00
[ ] tblKey {
2019-10-07 21:22:33 +00:00
tblKey { "lid" , "primary" , "" , false } ,
2018-12-17 04:58:55 +00:00
} ,
)
2018-12-14 04:08:53 +00:00
2019-10-06 22:20:37 +00:00
createTable ( "moderation_logs" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "action" , "varchar" , 100 , false , false , "" } ,
tC { "elementID" , "int" , 0 , false , false , "" } ,
tC { "elementType" , "varchar" , 100 , false , false , "" } ,
tC { "ipaddress" , "varchar" , 200 , false , false , "" } ,
tC { "actorID" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "doneAt" , "datetime" , 0 , false , false , "" } ,
2019-11-10 02:37:53 +00:00
tC { "extra" , "text" , 0 , false , false , "" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2017-10-16 07:32:58 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "administration_logs" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "action" , "varchar" , 100 , false , false , "" } ,
tC { "elementID" , "int" , 0 , false , false , "" } ,
tC { "elementType" , "varchar" , 100 , false , false , "" } ,
tC { "ipaddress" , "varchar" , 200 , false , false , "" } ,
tC { "actorID" , "int" , 0 , false , false , "" } , // TODO: Make this a foreign key
tC { "doneAt" , "datetime" , 0 , false , false , "" } ,
2019-11-10 02:37:53 +00:00
tC { "extra" , "text" , 0 , false , false , "" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2017-10-16 07:32:58 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "viewchunks" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "count" , "int" , 0 , false , false , "0" } ,
tC { "createdAt" , "datetime" , 0 , false , false , "" } ,
tC { "route" , "varchar" , 200 , false , false , "" } , // todo: set a default empty here
2019-01-21 12:27:59 +00:00
} , nil ,
2017-12-10 03:43:30 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "viewchunks_agents" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "count" , "int" , 0 , false , false , "0" } ,
tC { "createdAt" , "datetime" , 0 , false , false , "" } ,
tC { "browser" , "varchar" , 200 , false , false , "" } , // googlebot, firefox, opera, etc.
//tC{"version","varchar",0,false,false,""}, // the version of the browser or bot
2019-01-21 12:27:59 +00:00
} , nil ,
2018-01-09 07:39:29 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "viewchunks_systems" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "count" , "int" , 0 , false , false , "0" } ,
tC { "createdAt" , "datetime" , 0 , false , false , "" } ,
tC { "system" , "varchar" , 200 , false , false , "" } , // windows, android, unknown, etc.
2019-01-21 12:27:59 +00:00
} , nil ,
2018-02-05 10:29:13 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "viewchunks_langs" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "count" , "int" , 0 , false , false , "0" } ,
tC { "createdAt" , "datetime" , 0 , false , false , "" } ,
tC { "lang" , "varchar" , 200 , false , false , "" } , // en, ru, etc.
2019-01-21 12:27:59 +00:00
} , nil ,
2018-03-08 03:59:47 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "viewchunks_referrers" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "count" , "int" , 0 , false , false , "0" } ,
tC { "createdAt" , "datetime" , 0 , false , false , "" } ,
tC { "domain" , "varchar" , 200 , false , false , "" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2018-02-04 08:15:20 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "viewchunks_forums" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "count" , "int" , 0 , false , false , "0" } ,
tC { "createdAt" , "datetime" , 0 , false , false , "" } ,
tC { "forum" , "int" , 0 , false , false , "" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2018-02-19 04:26:01 +00:00
)
2017-12-19 03:53:13 +00:00
2019-10-06 22:20:37 +00:00
createTable ( "topicchunks" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "count" , "int" , 0 , false , false , "0" } ,
tC { "createdAt" , "datetime" , 0 , false , false , "" } ,
2018-01-18 12:31:25 +00:00
// TODO: Add a column for the parent forum?
2019-01-21 12:27:59 +00:00
} , nil ,
2018-01-18 12:31:25 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "postchunks" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "count" , "int" , 0 , false , false , "0" } ,
tC { "createdAt" , "datetime" , 0 , false , false , "" } ,
2018-01-14 12:03:20 +00:00
// TODO: Add a column for the parent topic / profile?
2019-01-21 12:27:59 +00:00
} , nil ,
2018-01-14 12:03:20 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "memchunks" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "count" , "int" , 0 , false , false , "0" } ,
tC { "stack" , "int" , 0 , false , false , "0" } ,
tC { "heap" , "int" , 0 , false , false , "0" } ,
tC { "createdAt" , "datetime" , 0 , false , false , "" } ,
2019-05-01 06:59:51 +00:00
} , nil ,
)
2019-10-06 22:20:37 +00:00
createTable ( "sync" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "last_update" , "datetime" , 0 , false , false , "" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2017-10-16 07:32:58 +00:00
)
2019-10-06 22:20:37 +00:00
createTable ( "updates" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "dbVersion" , "int" , 0 , false , false , "0" } ,
2019-01-21 12:27:59 +00:00
} , nil ,
2018-12-17 04:58:55 +00:00
)
2018-10-06 13:14:11 +00:00
2019-10-06 22:20:37 +00:00
createTable ( "meta" , "" , "" ,
2019-07-26 23:18:32 +00:00
[ ] tC {
tC { "name" , "varchar" , 200 , false , false , "" } ,
tC { "value" , "varchar" , 200 , false , false , "" } ,
2019-05-09 06:58:55 +00:00
} , nil ,
)
2019-10-06 22:20:37 +00:00
return err
2017-10-16 07:32:58 +00:00
}