if (!$ok) { break; } $TABLE_VERSION++; } table_Exit($table); } $table = 'SH_TABLE_NODE_META'; if (in_array(constant($table), $TABLE_LIST)) { $ok = null; // TEXT: 2^16 characters (65535) // TINYINT UNSIGNED: 0-255 table_Init($table); switch ($TABLE_VERSION) { case 0: $ok = table_Create($table, "CREATE TABLE " . SH_TABLE_PREFIX . constant($table) . " (\n\t\t\t\tid " . DB_TYPE_UID . ",\n\t\t\t\tnode " . DB_TYPE_ID . ",\n\t\t\t\t\tINDEX(node),\n\t\t\t\tscope TINYINT UNSIGNED NOT NULL,\n\t\t\t\t`key` " . DB_TYPE_ASCII(32) . ",\n\t\t\t\t`value` TEXT NOT NULL\n\t\t\t)" . DB_CREATE_SUFFIX); if (!$ok) { break; } $TABLE_VERSION++; } table_Exit($table); } /* $table = 'SH_TABLE_NODE_SEARCH'; if ( in_array(constant($table), $TABLE_LIST) ) { $ok = null; // Use ID only, but manually mirror what's in NODE (unique)? table_Init($table);
table_Exit($table); } $table = 'SH_TABLE_THEME_FINAL_VOTE'; if (in_array(constant($table), $TABLE_LIST)) { $ok = null; table_Init($table); switch ($TABLE_VERSION) { case 0: $ok = table_Create($table, "CREATE TABLE " . SH_TABLE_PREFIX . constant($table) . " (\n\t\t\t\tid " . DB_TYPE_UID . ",\n\t\t\t\tuser " . DB_TYPE_ID . ",\n\t\t\t\t\tINDEX(user),\n\t\t\t\tnode " . DB_TYPE_ID . ",\n\t\t\t\t\tINDEX(node),\n\t\t\t\t\tUNIQUE `user_node` (user,node),\n\t\t\t\ttimestamp " . DB_TYPE_TIMESTAMP . ",\n\t\t\t\tvalue INT NOT NULL,\n\t\t\t\t\tINDEX (value)\n\t\t\t)" . DB_CREATE_SUFFIX); if (!$ok) { break; } $TABLE_VERSION++; } table_Exit($table); } // *** // $table = 'SH_TABLE_THEME_HISTORY'; if (in_array(constant($table), $TABLE_LIST)) { $ok = null; table_Init($table); switch ($TABLE_VERSION) { case 0: $ok = table_Create($table, "CREATE TABLE " . SH_TABLE_PREFIX . constant($table) . " (\n\t\t\t\tid " . DB_TYPE_UID . ",\n\t\t\t\tnode " . DB_TYPE_ID . ",\n\t\t\t\tshorthand " . DB_TYPE_ASCII(20) . ",\n\t\t\t\tname " . DB_TYPE_UNICODE(64) . ",\n\t\t\t\ttheme " . DB_TYPE_UNICODE(64) . "\n\t\t\t)" . DB_CREATE_SUFFIX); if (!$ok) { break; } $TABLE_VERSION++; } table_Exit($table); }
<?php $table = 'SH_TABLE_GLOBAL'; if (in_array(constant($table), $TABLE_LIST)) { $ok = null; table_Init($table); switch ($TABLE_VERSION) { case 0: echo "Creating Table...\n"; $ok = table_Create($table, "CREATE TABLE " . SH_TABLE_PREFIX . constant($table) . " (\n\t\t\t\tid " . DB_TYPE_UID . ",\n\t\t\t\t`key` " . DB_TYPE_ASCII(64) . " DEFAULT '',\n\t\t\t\t\tINDEX(`key`),\n\t\t\t\t`value` " . DB_TYPE_UNICODE(128) . " DEFAULT '',\n\t\t\t\ttimestamp " . DB_TYPE_TIMESTAMP . "\n\t\t\t)" . DB_CREATE_SUFFIX); if (!$ok) { break; } $TABLE_VERSION++; case 1: $ok = table_Nop($table); if (!$ok) { break; } $TABLE_VERSION++; } // Because this is Global, we do a few more things // $global_default = array_merge($SH_GLOBAL_DEFAULT, array_fill_keys(global_GetTableConstants(), 0)); // Add elements found in the defaults that don't exist yet // $global_diff = array_diff_key($global_default, $SH); $global_diff_count = count($global_diff); if ($global_diff_count > 0) { print "Adding " . $global_diff_count . " missing element(s) to " . $table . "\n"; foreach ($global_diff as $key => $value) { print " * " . $key . " = " . (is_string($value) ? "\"" . $value . "\"\n" : $value . "\n"); global_Set($key, $value);
// - MySQL index limit: 767 bytes (or 256*3-1) // - Recommended minimum password length: 12-14 - https://en.wikipedia.org/wiki/Password_strength#Random_passwords // NOTES: // - E-mail addresses are 24bit (3 byte) Unicode, so emoji in addresses wont work. To fit in the MySQL index limit. // - E-mail addresses must be unique! // - We now have a separate id and node member. This is so we can associate multiple e-mails with 1 account. // - When you create an account, no node is created. 'node' is 0. // - After activating an account, create a node, and set it. // - If hash is an empty string, always fail // // - TODO: you can purge any accounts with a 'node' of 0, and an age of 1 month. // - Encode/decoding the secret will require funky code (mysql CONV(...). HEX and UNHEX don't do it) table_Init($table); switch ($TABLE_VERSION) { case 0: $ok = table_Create($table, "CREATE TABLE " . SH_TABLE_PREFIX . constant($table) . " (\n\t\t\t\tid " . DB_TYPE_UID . ",\n\t\t\t\tnode " . DB_TYPE_ID . ",\n\t\t\t\t\tINDEX(node),\n\t\t\t\tmail " . DB_TYPE_UNICODE3(254) . ",\n\t\t\t\t\tUNIQUE(mail),\n\t\t\t\tcreated " . DB_TYPE_TIMESTAMP . ",\n\t\t\t\thash " . DB_TYPE_ASCII(255) . ",\n\t\t\t\tsecret VARBINARY(20) NOT NULL,\n\t\t\t\t\n\t\t\t\tauth_key " . DB_TYPE_ASCII(32 * 2) . ",\n\t\t\t\tlast_auth " . DB_TYPE_TIMESTAMP . "\n\t\t\t)" . DB_CREATE_SUFFIX); if (!$ok) { break; } $TABLE_VERSION++; } table_Exit($table); } // User Access Log $table = 'SH_TABLE_USER_ACCESS'; if (in_array(constant($table), $TABLE_LIST)) { $ok = null; table_Init($table); switch ($TABLE_VERSION) { case 0: $ok = table_Create($table, "CREATE TABLE " . SH_TABLE_PREFIX . constant($table) . " (\n\t\t\t\tid " . DB_TYPE_UID . ",\n\t\t\t\tuser " . DB_TYPE_ID . ",\n\t\t\t\t\tINDEX(user),\n\t\t\t\tip " . DB_TYPE_IP . ",\n\t\t\t\t\tINDEX(ip),\n\t\t\t\ttimestamp " . DB_TYPE_TIMESTAMP . ",\n\t\t\t\t\tINDEX(timestamp),\n\t\t\t\tvalue " . DB_TYPE_INT32 . "\n\t\t\t)" . DB_CREATE_SUFFIX);