xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / inc / db / struct.inc.php (f359fb8f6b8769dae5f907389f922916dded3b1f) (3,650B) (mode 100644) [raw]
<?php
$rg_sql_schema_ver = 1;

$rg_sql_struct = array();
$rg_sql_struct[0] = array();
$rg_sql_struct[0]['tables'] = array(
	"repos" => "CREATE TABLE repos"
		. " (repo_id SERIAL PRIMARY KEY"
		. ", name TEXT UNIQUE NOT NULL"
		. ", uid INTEGER NOT NULL"
		. ", itime INTEGER NOT NULL"
		. ", disk_quota_mb INTEGER DEFAULT 0"
		. ", disk_used_mb INTEGER NOT NULL DEFAULT 0"
		. ", max_commit_size INTEGER DEFAULT 0"
		. ", master INTEGER NOT NULL DEFAULT 0"
		. ", description TEXT NOT NULL DEFAULT ''"
		. ", git_dir_done INTEGER NOT NULL DEFAULT 0"
		. ", default_rights TEXT NOT NULL DEFAULT ''"
		. ", deleted INTEGER NOT NULL DEFAULT 0"
		. ", max_users INTEGER NOT NULL DEFAULT 0"
		. ")",
	"rights" => "CREATE TABLE rights"
		. " (type TEXT NOT NULL"
		. ", obj_id INTEGER NOT NULL"
		. ", uid INTEGER NOT NULL"
		. ", rights TEXT NOT NULL"
		. ", itime INTEGER NOT NULL)",
	"state" => "CREATE TABLE state"
		. " (var TEXT PRIMARY KEY"
		. ", value TEXT NOT NULL)",
	"keys" => "CREATE TABLE keys"
		. " (key_id SERIAL PRIMARY KEY"
		. ", itime INTEGER NOT NULL"
		. ", uid INTEGER NOT NULL"
		. ", key TEXT UNIQUE NOT NULL)",
	"users" => "CREATE TABLE users"
		. " (uid SERIAL PRIMARY KEY"
		. ", username TEXT UNIQUE NOT NULL"
		. ", salt TEXT NOT NULL"
		. ", pass TEXT NOT NULL"
		. ", email TEXT NOT NULL"
		. ", itime INTEGER NOT NULL"
		. ", suspended INTEGER NOT NULL DEFAULT 0"
		. ", session_time INTEGER NOT NULL DEFAULT 3600"
		. ", last_seen INTEGER NOT NULL DEFAULT 0"
		. ", is_admin INTEGER NOT NULL DEFAULT 0"
		. ", disk_quota_mb INTEGER NOT NULL DEFAULT 0"
		. ", disk_used_mb INTEGER NOT NULL DEFAULT 0"
		. ", rights TEXT NOT NULL"
		. ", confirmed INTEGER NOT NULL DEFAULT 0"
		. ", confirm_token TEXT NOT NULL DEFAULT ''"
		. ")",
	"sess" => "CREATE TABLE sess"
		. " (sid TEXT PRIMARY KEY"
		. ", uid INTEGER NOT NULL"
		. ", expire INTEGER NOT NULL"
		. ", session_time INTEGER NOT NULL"
		. ", ip TEXT NOT NULL)",
	"forgot_pass" => "CREATE TABLE forgot_pass"
		. " (token TEXT PRIMARY KEY"
		. ", uid INTEGER NOT NULL"
		. ", expire INTEGER NOT NULL)",
	"tokens" => "CREATE TABLE tokens"
		. " (token TEXT PRIMARY KEY"
		. ", sid TEXT NOT NULL"
		. ", expire INTEGER NOT NULL)"
);
$rg_sql_struct[0]['other'] = array();

$rg_sql_struct[1] = array();
$rg_sql_struct[1]['tables'] = array(
	"suggestions" => "CREATE TABLE suggestions"
		. " (suggestion_id SERIAL PRIMARY KEY"
		. ", uid INTEGER NOT NULL"
		. ", email TEXT NOT NULL"
		. ", suggestion TEXT NOT NULL)"
);
$rg_sql_struct[1]['other'] = array();

/*
 * Generate structure
 */
function rg_sql_struct_run($db, $ignore_errors, $drop_tables, $old_schema_ver)
{
	global $rg_sql_struct;
	global $rg_sql_schema_ver;

	rg_log("sql_struct_run:"
		. " ignore_errors=" . ($ignore_errors ? "Yes" : "No")
		. " drop_tables=" . ($drop_tables ? "Yes" : "No")
		. " old_schema_ver=$old_schema_ver...");

	for ($i = $old_schema_ver; $i <= $rg_sql_schema_ver; $i++) {
		foreach ($rg_sql_struct[$i] as $type => $sqls) {
			if (count($sqls) == 0)
				continue;

			foreach ($sqls as $id => $sql) {
				rg_log("Applying schema $i, type $type, id $id...");

				if ((strcmp($type, "tables") == 0)
					&& ($drop_tables === TRUE)) {
					rg_log("Dropping table [$id]...");
					$sql2 = "DROP TABLE IF EXISTS $id";
					$res = rg_sql_query($db, $sql2);
					rg_sql_free_result($res);
				}

				rg_log("Running [$sql]...");
				$res = rg_sql_query($db, $sql);
				if ($res === FALSE) {
					rg_log("WARN: Cannot run sql ($sql) (" . rg_sql_error() . ")!");
					if (!$ignore_errors)
						return FALSE;
				} else {
					rg_sql_free_result($res);
				}
			}
		}
	}

	return TRUE;
}

?>
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master