eliminate more boilerplate in tables.go

This commit is contained in:
Azareal 2021-01-07 19:15:39 +10:00
parent 1137d94d5b
commit e792dbc2c7
1 changed files with 73 additions and 72 deletions

View File

@ -532,21 +532,21 @@ func createTables2(a qgen.Adapter, f func(table, charset, collation string, colu
// replacement for elementType // replacement for elementType
tC{"elementTable", "int", 0, false, false, "0"}, tC{"elementTable", "int", 0, false, false, "0"},
tC{"elementID", "int", 0, false, false, ""}, /* the ID of the element being acted upon */ {"elementID", "int", 0, false, false, ""}, /* the ID of the element being acted upon */
createdAt(), createdAt(),
ccol("extra", 200, "''"), ccol("extra", 200, "''"),
}, },
[]tK{ []tK{
tK{"asid", "primary", "", false}, {"asid", "primary", "", false},
}, },
) )
createTable("activity_subscriptions", "", "", createTable("activity_subscriptions", "", "",
[]tC{ []tC{
tC{"user", "int", 0, false, false, ""}, // TODO: Make this a foreign key {"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 */ {"targetID", "int", 0, false, false, ""}, /* the ID of the element being acted upon */
ccol("targetType", 50, ""), /* topic, post (calling it post here to differentiate it from the 'reply' event), forum, user */ ccol("targetType", 50, ""), /* 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*/ {"level", "int", 0, false, false, "0"}, /* 0: Mentions (aka the global default for any post), 1: Replies To You, 2: All Replies*/
}, nil, }, nil,
) )
@ -558,19 +558,19 @@ func createTables2(a qgen.Adapter, f func(table, charset, collation string, colu
ccol("type", 50, ""), ccol("type", 50, ""),
ccol("constraints", 200, "''"), ccol("constraints", 200, "''"),
}, },
[]tblKey{ []tK{
tblKey{"name", "unique", "", false}, {"name", "unique", "", false},
}, },
) )
createTable("word_filters", "", "", createTable("word_filters", "", "",
[]tC{ []tC{
tC{"wfid", "int", 0, false, true, ""}, {"wfid", "int", 0, false, true, ""},
ccol("find", 200, ""), ccol("find", 200, ""),
ccol("replacement", 200, ""), ccol("replacement", 200, ""),
}, },
[]tblKey{ []tK{
tblKey{"wfid", "primary", "", false}, {"wfid", "primary", "", false},
}, },
) )
@ -580,8 +580,8 @@ func createTables2(a qgen.Adapter, f func(table, charset, collation string, colu
bcol("active", false), bcol("active", false),
bcol("installed", false), bcol("installed", false),
}, },
[]tblKey{ []tK{
tblKey{"uname", "unique", "", false}, {"uname", "unique", "", false},
}, },
) )
@ -591,39 +591,39 @@ func createTables2(a qgen.Adapter, f func(table, charset, collation string, colu
bcol("default", false), bcol("default", false),
//text("profileUserVars"), //text("profileUserVars"),
}, },
[]tblKey{ []tK{
tblKey{"uname", "unique", "", false}, {"uname", "unique", "", false},
}, },
) )
createTable("widgets", "", "", createTable("widgets", "", "",
[]tC{ []tC{
tC{"wid", "int", 0, false, true, ""}, {"wid", "int", 0, false, true, ""},
tC{"position", "int", 0, false, false, ""}, {"position", "int", 0, false, false, ""},
ccol("side", 100, ""), ccol("side", 100, ""),
ccol("type", 100, ""), ccol("type", 100, ""),
bcol("active", false), bcol("active", false),
ccol("location", 100, ""), ccol("location", 100, ""),
text("data"), text("data"),
}, },
[]tblKey{ []tK{
tblKey{"wid", "primary", "", false}, {"wid", "primary", "", false},
}, },
) )
createTable("menus", "", "", createTable("menus", "", "",
[]tC{ []tC{
tC{"mid", "int", 0, false, true, ""}, {"mid", "int", 0, false, true, ""},
}, },
[]tblKey{ []tK{
tblKey{"mid", "primary", "", false}, {"mid", "primary", "", false},
}, },
) )
createTable("menu_items", "", "", createTable("menu_items", "", "",
[]tC{ []tC{
tC{"miid", "int", 0, false, true, ""}, {"miid", "int", 0, false, true, ""},
tC{"mid", "int", 0, false, false, ""}, {"mid", "int", 0, false, false, ""},
ccol("name", 200, "''"), ccol("name", 200, "''"),
ccol("htmlID", 200, "''"), ccol("htmlID", 200, "''"),
ccol("cssClass", 200, "''"), ccol("cssClass", 200, "''"),
@ -632,7 +632,7 @@ func createTables2(a qgen.Adapter, f func(table, charset, collation string, colu
ccol("aria", 200, "''"), ccol("aria", 200, "''"),
ccol("tooltip", 200, "''"), ccol("tooltip", 200, "''"),
ccol("tmplName", 200, "''"), ccol("tmplName", 200, "''"),
tC{"order", "int", 0, false, false, "0"}, {"order", "int", 0, false, false, "0"},
bcol("guestOnly", false), bcol("guestOnly", false),
bcol("memberOnly", false), bcol("memberOnly", false),
@ -640,62 +640,63 @@ func createTables2(a qgen.Adapter, f func(table, charset, collation string, colu
bcol("adminOnly", false), bcol("adminOnly", false),
}, },
[]tK{ []tK{
tK{"miid", "primary", "", false}, {"miid", "primary", "", false},
}, },
) )
createTable("pages", mysqlPre, mysqlCol, createTable("pages", mysqlPre, mysqlCol,
[]tC{ []tC{
tC{"pid", "int", 0, false, true, ""}, {"pid", "int", 0, false, true, ""},
//ccol("path", 200, ""), //ccol("path", 200, ""),
ccol("name", 200, ""), ccol("name", 200, ""),
ccol("title", 200, ""), ccol("title", 200, ""),
text("body"), text("body"),
// TODO: Make this a table? // TODO: Make this a table?
text("allowedGroups"), text("allowedGroups"),
tC{"menuID", "int", 0, false, false, "-1"}, // simple sidebar menu {"menuID", "int", 0, false, false, "-1"}, // simple sidebar menu
}, },
[]tK{ []tK{
tK{"pid", "primary", "", false}, {"pid", "primary", "", false},
}, },
) )
createTable("registration_logs", "", "", createTable("registration_logs", "", "",
[]tC{ []tC{
tC{"rlid", "int", 0, false, true, ""}, {"rlid", "int", 0, false, true, ""},
ccol("username", 100, ""), ccol("username", 100, ""),
tC{"email", "varchar", 100, false, false, ""}, {"email", "varchar", 100, false, false, ""},
ccol("failureReason", 100, ""), ccol("failureReason", 100, ""),
bcol("success", false), // Did this attempt succeed? bcol("success", false), // Did this attempt succeed?
ccol("ipaddress", 200, ""), ccol("ipaddress", 200, ""),
createdAt("doneAt"), createdAt("doneAt"),
}, },
[]tblKey{ []tblKey{
tblKey{"rlid", "primary", "", false}, {"rlid", "primary", "", false},
}, },
) )
createTable("login_logs", "", "", createTable("login_logs", "", "",
[]tC{ []tC{
tC{"lid", "int", 0, false, true, ""}, {"lid", "int", 0, false, true, ""},
tC{"uid", "int", 0, false, false, ""}, {"uid", "int", 0, false, false, ""},
bcol("success", false), // Did this attempt succeed? bcol("success", false), // Did this attempt succeed?
ccol("ipaddress", 200, ""), ccol("ipaddress", 200, ""),
createdAt("doneAt"), createdAt("doneAt"),
}, },
[]tblKey{ []tblKey{
tblKey{"lid", "primary", "", false}, {"lid", "primary", "", false},
}, },
) )
createTable("moderation_logs", "", "", createTable("moderation_logs", "", "",
[]tC{ []tC{
ccol("action", 100, ""), ccol("action", 100, ""),
tC{"elementID", "int", 0, false, false, ""}, {"elementID", "int", 0, false, false, ""},
ccol("elementType", 100, ""), ccol("elementType", 100, ""),
ccol("ipaddress", 200, ""), ccol("ipaddress", 200, ""),
tC{"actorID", "int", 0, false, false, ""}, // TODO: Make this a foreign key {"actorID", "int", 0, false, false, ""}, // TODO: Make this a foreign key
tC{"doneAt", "datetime", 0, false, false, ""}, {"doneAt", "datetime", 0, false, false, ""},
text("extra"), text("extra"),
}, nil, }, nil,
) )
@ -703,28 +704,28 @@ func createTables2(a qgen.Adapter, f func(table, charset, collation string, colu
createTable("administration_logs", "", "", createTable("administration_logs", "", "",
[]tC{ []tC{
ccol("action", 100, ""), ccol("action", 100, ""),
tC{"elementID", "int", 0, false, false, ""}, {"elementID", "int", 0, false, false, ""},
ccol("elementType", 100, ""), ccol("elementType", 100, ""),
ccol("ipaddress", 200, ""), ccol("ipaddress", 200, ""),
tC{"actorID", "int", 0, false, false, ""}, // TODO: Make this a foreign key {"actorID", "int", 0, false, false, ""}, // TODO: Make this a foreign key
tC{"doneAt", "datetime", 0, false, false, ""}, {"doneAt", "datetime", 0, false, false, ""},
text("extra"), text("extra"),
}, nil, }, nil,
) )
createTable("viewchunks", "", "", createTable("viewchunks", "", "",
[]tC{ []tC{
tC{"count", "int", 0, false, false, "0"}, {"count", "int", 0, false, false, "0"},
tC{"avg", "int", 0, false, false, "0"}, {"avg", "int", 0, false, false, "0"},
tC{"createdAt", "datetime", 0, false, false, ""}, {"createdAt", "datetime", 0, false, false, ""},
ccol("route", 200, ""), // TODO: set a default empty here ccol("route", 200, ""), // TODO: set a default empty here
}, nil, }, nil,
) )
createTable("viewchunks_agents", "", "", createTable("viewchunks_agents", "", "",
[]tC{ []tC{
tC{"count", "int", 0, false, false, "0"}, {"count", "int", 0, false, false, "0"},
tC{"createdAt", "datetime", 0, false, false, ""}, {"createdAt", "datetime", 0, false, false, ""},
ccol("browser", 200, ""), // googlebot, firefox, opera, etc. ccol("browser", 200, ""), // googlebot, firefox, opera, etc.
//ccol("version",0,""), // the version of the browser or bot //ccol("version",0,""), // the version of the browser or bot
}, nil, }, nil,
@ -732,79 +733,79 @@ func createTables2(a qgen.Adapter, f func(table, charset, collation string, colu
createTable("viewchunks_systems", "", "", createTable("viewchunks_systems", "", "",
[]tC{ []tC{
tC{"count", "int", 0, false, false, "0"}, {"count", "int", 0, false, false, "0"},
tC{"createdAt", "datetime", 0, false, false, ""}, {"createdAt", "datetime", 0, false, false, ""},
ccol("system", 200, ""), // windows, android, unknown, etc. ccol("system", 200, ""), // windows, android, unknown, etc.
}, nil, }, nil,
) )
createTable("viewchunks_langs", "", "", createTable("viewchunks_langs", "", "",
[]tC{ []tC{
tC{"count", "int", 0, false, false, "0"}, {"count", "int", 0, false, false, "0"},
tC{"createdAt", "datetime", 0, false, false, ""}, {"createdAt", "datetime", 0, false, false, ""},
ccol("lang", 200, ""), // en, ru, etc. ccol("lang", 200, ""), // en, ru, etc.
}, nil, }, nil,
) )
createTable("viewchunks_referrers", "", "", createTable("viewchunks_referrers", "", "",
[]tC{ []tC{
tC{"count", "int", 0, false, false, "0"}, {"count", "int", 0, false, false, "0"},
tC{"createdAt", "datetime", 0, false, false, ""}, {"createdAt", "datetime", 0, false, false, ""},
ccol("domain", 200, ""), ccol("domain", 200, ""),
}, nil, }, nil,
) )
createTable("viewchunks_forums", "", "", createTable("viewchunks_forums", "", "",
[]tC{ []tC{
tC{"count", "int", 0, false, false, "0"}, {"count", "int", 0, false, false, "0"},
tC{"createdAt", "datetime", 0, false, false, ""}, {"createdAt", "datetime", 0, false, false, ""},
tC{"forum", "int", 0, false, false, ""}, {"forum", "int", 0, false, false, ""},
}, nil, }, nil,
) )
createTable("topicchunks", "", "", createTable("topicchunks", "", "",
[]tC{ []tC{
tC{"count", "int", 0, false, false, "0"}, {"count", "int", 0, false, false, "0"},
tC{"createdAt", "datetime", 0, false, false, ""}, {"createdAt", "datetime", 0, false, false, ""},
// TODO: Add a column for the parent forum? // TODO: Add a column for the parent forum?
}, nil, }, nil,
) )
createTable("postchunks", "", "", createTable("postchunks", "", "",
[]tC{ []tC{
tC{"count", "int", 0, false, false, "0"}, {"count", "int", 0, false, false, "0"},
tC{"createdAt", "datetime", 0, false, false, ""}, {"createdAt", "datetime", 0, false, false, ""},
// TODO: Add a column for the parent topic / profile? // TODO: Add a column for the parent topic / profile?
}, nil, }, nil,
) )
createTable("memchunks", "", "", createTable("memchunks", "", "",
[]tC{ []tC{
tC{"count", "int", 0, false, false, "0"}, {"count", "int", 0, false, false, "0"},
tC{"stack", "int", 0, false, false, "0"}, {"stack", "int", 0, false, false, "0"},
tC{"heap", "int", 0, false, false, "0"}, {"heap", "int", 0, false, false, "0"},
tC{"createdAt", "datetime", 0, false, false, ""}, {"createdAt", "datetime", 0, false, false, ""},
}, nil, }, nil,
) )
createTable("perfchunks", "", "", createTable("perfchunks", "", "",
[]tC{ []tC{
tC{"low", "int", 0, false, false, "0"}, {"low", "int", 0, false, false, "0"},
tC{"high", "int", 0, false, false, "0"}, {"high", "int", 0, false, false, "0"},
tC{"avg", "int", 0, false, false, "0"}, {"avg", "int", 0, false, false, "0"},
tC{"createdAt", "datetime", 0, false, false, ""}, {"createdAt", "datetime", 0, false, false, ""},
}, nil, }, nil,
) )
createTable("sync", "", "", createTable("sync", "", "",
[]tC{ []tC{
tC{"last_update", "datetime", 0, false, false, ""}, {"last_update", "datetime", 0, false, false, ""},
}, nil, }, nil,
) )
createTable("updates", "", "", createTable("updates", "", "",
[]tC{ []tC{
tC{"dbVersion", "int", 0, false, false, "0"}, {"dbVersion", "int", 0, false, false, "0"},
}, nil, }, nil,
) )
@ -817,12 +818,12 @@ func createTables2(a qgen.Adapter, f func(table, charset, collation string, colu
/*createTable("tables", "", "", /*createTable("tables", "", "",
[]tC{ []tC{
tC{"id", "int", 0, false, true, ""}, {"id", "int", 0, false, true, ""},
ccol("name", 200, ""), ccol("name", 200, ""),
}, },
[]tK{ []tK{
tK{"id", "primary", "", false}, {"id", "primary", "", false},
tK{"name", "unique", "", false}, {"name", "unique", "", false},
}, },
)*/ )*/