Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

anniemaybytes/chihaya #60

Open
wants to merge 40 commits into
base: production
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0006bdc
empty
pjc09h Apr 11, 2023
478cb5f
Merge branch 'production' of github.com:biotorrents/gazelle into chihaya
pjc09h Apr 12, 2023
1000108
Merge branch 'production' of github.com:biotorrents/gazelle into chihaya
pjc09h May 12, 2023
7e1c3ee
login query hotfix
pjc09h May 17, 2023
fc023a0
update composer
pjc09h May 19, 2023
cd2cb37
Merge branch 'production' of github.com:biotorrents/gazelle into crea…
pjc09h May 20, 2023
2e62b13
silly laravel
pjc09h May 20, 2023
e2c8a7f
long-forlorn api
pjc09h May 20, 2023
0c0d036
improve binary handling a bit
pjc09h May 20, 2023
032d30a
upsert
pjc09h May 20, 2023
abd9cdb
it works
pjc09h May 20, 2023
a222f88
pseudo orm
pjc09h May 20, 2023
e60b07b
put the cache key algorithm in one place
pjc09h May 20, 2023
153a0b9
fix the internal api
pjc09h May 20, 2023
f995aba
bearer token scopes ground work
pjc09h May 20, 2023
3d549c1
cleanup
pjc09h May 20, 2023
a22a3d3
refactor, but there's a bug in token validation
pjc09h May 20, 2023
960267c
various optimizations
pjc09h May 20, 2023
0b17ee0
improve token scopes
pjc09h May 20, 2023
70ceeb7
start implementing a real api response spec
pjc09h May 20, 2023
66f1fbf
use application/vnd.api+json
pjc09h May 20, 2023
dccc822
add openapi.json
pjc09h May 20, 2023
68583c8
start fleshing out an openapi spec
pjc09h May 20, 2023
d1d6023
Merge branch 'creatorObjects' of github.com:biotorrents/gazelle into …
pjc09h May 20, 2023
7ad2e8e
openapi stuff
pjc09h May 20, 2023
846eafb
base responses
pjc09h May 20, 2023
47cb1b9
start crudding stuff up for real
pjc09h May 21, 2023
9d43886
clean out the old api
pjc09h May 21, 2023
9d922d0
mock up some more crud stuff
pjc09h May 21, 2023
481c28e
more crud scaffolding
pjc09h May 21, 2023
f65896d
empty commit
pjc09h May 28, 2023
b15f178
Merge branch 'development' of github.com:biotorrents/gazelle into chi…
pjc09h May 28, 2023
12f059e
add schema file
pjc09h May 28, 2023
70c1d3a
draft migration
pjc09h May 28, 2023
8c87cc3
fix
pjc09h May 29, 2023
5089c35
now to fix all the inevitable bugs
pjc09h May 29, 2023
34307c3
fix client whitelist
pjc09h May 29, 2023
2447424
fix the misc values thing
pjc09h May 29, 2023
1b1057c
"fix" the service stats
pjc09h May 29, 2023
5508efe
more little deletions
pjc09h May 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
draft migration
  • Loading branch information
pjc09h committed May 28, 2023
commit 70c1d3ac8640b9bdd2d2f04ec9572d25da405961
312 changes: 312 additions & 0 deletions database/migrations/20230528195005_chihaya_schema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class ChihayaSchema extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$app = \Gazelle\App::go();

/**
* approved_clients
*
* create table approved_clients
* (
* id mediumint unsigned auto_increment primary key,
* peer_id varchar(42) null,
* archived tinyint(1) default 0 null
* );
*/
$table = $this->table("approved_clients");
$table
->addColumn("uuid", "binary", [
"length" => 16,
"default" => Phinx\Util\Literal::from("unhex(replace(uuid(), '-', ''))"),
"null" => false,
])

->addColumn("peer_id", "string", ["limit" => 64, "null" => true])
->addColumn("archived", "boolean", ["default" => false, "null" => true])

->addColumn("created_at", "datetime", ["default" => "CURRENT_TIMESTAMP"])
->addColumn("updated_at", "datetime", ["null" => true, "update" => "CURRENT_TIMESTAMP"])
->addColumn("deleted_at", "datetime", ["null" => true])

->create();

/**
* mod_core
*
* create table mod_core
* (
* mod_option varchar(121) not null primary key,
* mod_setting int(12) default 0 not null
* );
*/
$table = $this->table("mod_core");
$table
->addColumn("uuid", "binary", [
"length" => 16,
"default" => Phinx\Util\Literal::from("unhex(replace(uuid(), '-', ''))"),
"null" => false,
])

->addColumn("mod_option", "string", ["limit" => 128, "null" => false])
->addColumn("archived", "integer", ["default" => 0, "null" => false])

->addColumn("created_at", "datetime", ["default" => "CURRENT_TIMESTAMP"])
->addColumn("updated_at", "datetime", ["null" => true, "update" => "CURRENT_TIMESTAMP"])
->addColumn("deleted_at", "datetime", ["null" => true])

->addIndex(["mod_option"], ["unique" => true])

->create();

/**
* torrent_group_freeleech
*
* create table torrent_group_freeleech
* (
* ID int(10) auto_increment primary key,
* GroupID int(10) default 0 not null,
* Type enum ('anime', 'music') default 'anime' not null,
* DownMultiplier float default 1 not null,
* UpMultiplier float default 1 not null,
* constraint GroupID unique (GroupID, Type)
* );
*/
$table = $this->table("torrent_group_freeleech");
$table
->addColumn("uuid", "binary", [
"length" => 16,
"default" => Phinx\Util\Literal::from("unhex(replace(uuid(), '-', ''))"),
"null" => false,
])

->addColumn("groupId", "integer", ["default" => 0, "null" => false])
->addColumn("type", "string", ["limit" => 32, "default" => "", "null" => false])
->addColumn("downMultiplier", "float", ["default" => 1, "null" => false])
->addColumn("upMultiplier", "float", ["default" => 1, "null" => false])

->addColumn("created_at", "datetime", ["default" => "CURRENT_TIMESTAMP"])
->addColumn("updated_at", "datetime", ["null" => true, "update" => "CURRENT_TIMESTAMP"])
->addColumn("deleted_at", "datetime", ["null" => true])

->addForeignKey("groupId", "torrents_group", ["id"], ["constraint" => "groupId"])

->create();

/**
* torrents
*
* create table torrents
* (
* ID int(10) auto_increment primary key,
* GroupID int(10) not null,
* TorrentType enum ('anime', 'music') default 'anime' not null,
* info_hash blob not null,
* Leechers int(6) default 0 not null,
* Seeders int(6) default 0 not null,
* last_action int default 0 not null,
* Snatched int unsigned default 0 not null,
* DownMultiplier float default 1 not null,
* UpMultiplier float default 1 not null,
* Status int default 0 not null,
* constraint InfoHash unique (info_hash)
* );
*/
$table = $this->table("torrents");
$table
->addColumn("torrentType", "string", ["limit" => 32, "default" => "", "null" => false, "after" => "anonymous"])
->addColumn("downMultiplier", "float", ["default" => 1, "null" => false, "after" => "snatched"])
->addColumn("upMultiplier", "float", ["default" => 1, "null" => false, "after" => "downMultiplier"])
->addColumn("status", "integer", ["default" => 0, "null" => false, "after" => "upMultiplier"])

# todo: add constraint

->update();

/**
* torrents_group
*
* create table torrents_group
* (
* ID int unsigned auto_increment primary key,
* Time int(10) default 0 not null
* ) charset = utf8mb4;
*/
$table = $this->table("torrents_group");
$table
->addColumn("time", "integer", ["default" => 0, "null" => false, "after" => "upMultiplier"])

#->renameColumn("timestamp", "time")
#->changeColumn("time", "integer", ["default" => 0, "null" => false, "after" => "timestamp"])

->update();

/**
* transfer_history
*
* create table transfer_history
* (
* uid int default 0 not null,
* fid int default 0 not null,
* uploaded bigint default 0 not null,
* downloaded bigint default 0 not null,
* seeding tinyint default 0 not null,
* seedtime int(30) default 0 not null,
* activetime int(30) default 0 not null,
* hnr tinyint default 0 not null,
* remaining bigint default 0 not null,
* active tinyint default 0 not null,
* starttime int default 0 not null,
* last_announce int default 0 not null,
* snatched int default 0 not null,
* snatched_time int default 0 null,
* primary key (uid, fid)
* );
*
* PRIMARY KEY (`uid`,`fid`),
* KEY `active` (`active`),
* KEY `seeding` (`seeding`,`active`),
* KEY `hnr` (`hnr`),
* KEY `ss` (`snatched_time`,`snatched`),
* KEY `fid` (`fid`),
* KEY `transfer` (`uploaded`,`downloaded`),
* KEY `snatched` (`snatched`),
* KEY `last_announce` (`active`,`last_announce`),
* KEY `time` (`last_announce`,`seedtime`,`activetime`)
*/
$table = $this->table("transfer_history");
$table
->addColumn("uuid", "binary", [
"length" => 16,
"default" => Phinx\Util\Literal::from("unhex(replace(uuid(), '-', ''))"),
"null" => false,
])

->addColumn("uid", "integer", ["default" => 0, "null" => false])
->addColumn("fid", "integer", ["default" => 0, "null" => false])
->addColumn("uploaded", "biginteger", ["default" => 0, "null" => false])
->addColumn("downloaded", "biginteger", ["default" => 0, "null" => false])
->addColumn("seeding", "boolean", ["default" => false, "null" => false])
->addColumn("seedTime", "biginteger", ["default" => 0, "null" => false])
->addColumn("activeTime", "biginteger", ["default" => 0, "null" => false])
->addColumn("hnr", "boolean", ["default" => false, "null" => false])
->addColumn("remaining", "biginteger", ["default" => 0, "null" => false])
->addColumn("active", "boolean", ["default" => false, "null" => false])
->addColumn("startTime", "integer", ["default" => 0, "null" => false])
->addColumn("last_announce", "integer", ["default" => 0, "null" => false])
->addColumn("snatched", "integer", ["default" => 0, "null" => false])
->addColumn("snatched_time", "integer", ["default" => 0, "null" => false])

->addColumn("created_at", "datetime", ["default" => "CURRENT_TIMESTAMP"])
->addColumn("updated_at", "datetime", ["null" => true, "update" => "CURRENT_TIMESTAMP"])
->addColumn("deleted_at", "datetime", ["null" => true])

->addIndex(["uid", "fid"])
->addIndex(["active"])
->addIndex(["seeding", "active"], ["name" => "seeding"])
->addIndex(["hnr"])
->addIndex(["snatched_time", "snatched"], ["name" => "ss"])
->addIndex(["fid"])
->addIndex(["uploaded", "downloaded"], ["name" => "transfer"])
->addIndex(["snatched"])
->addIndex(["active", "last_announce"], ["name" => "last_announce"])
->addIndex(["last_announce", "seedTime", "activeTime"], ["name" => "time"])

->create();

/**
* transfer_ips
*
* create table transfer_ips
* (
* last_announce int unsigned default 0 not null,
* starttime int unsigned default 0 not null,
* uid int unsigned default 0 not null,
* fid int unsigned default 0 not null,
* ip int unsigned default 0 not null,
* client_id mediumint unsigned default 0 not null,
* uploaded bigint unsigned default 0 not null,
* downloaded bigint unsigned default 0 not null,
* port smallint unsigned zerofill null,
* primary key (uid, fid, ip, client_id)
* );
*
* PRIMARY KEY (`uid`,`fid`,`ip`,`client_id`),
* KEY `last_announce` (`last_announce`)
*/
$table = $this->table("transfer_ips");
$table
->addColumn("uuid", "binary", [
"length" => 16,
"default" => Phinx\Util\Literal::from("unhex(replace(uuid(), '-', ''))"),
"null" => false,
])

->addColumn("last_announce", "integer", ["default" => 0, "null" => false])
->addColumn("startTime", "integer", ["default" => 0, "null" => false])
->addColumn("uid", "integer", ["default" => 0, "null" => false])
->addColumn("fid", "integer", ["default" => 0, "null" => false])
->addColumn("ip", "integer", ["default" => 0, "null" => false])
->addColumn("client_id", "smallinteger", ["default" => 0, "null" => false])
->addColumn("uploaded", "biginteger", ["default" => 0, "null" => false])
->addColumn("downloaded", "biginteger", ["default" => 0, "null" => false])
->addColumn("port", "smallinteger", ["default" => 0, "null" => false])

->addColumn("created_at", "datetime", ["default" => "CURRENT_TIMESTAMP"])
->addColumn("updated_at", "datetime", ["null" => true, "update" => "CURRENT_TIMESTAMP"])
->addColumn("deleted_at", "datetime", ["null" => true])

->addIndex(["uid", "fid", "ip", "client_id"])
->addIndex(["last_announce"])

->create();

/**
* users_main
*
* create table users_main
* (
* ID int unsigned auto_increment primary key,
* Uploaded bigint unsigned default 0 not null,
* Downloaded bigint unsigned default 0 not null,
* Enabled enum ('0', '1', '2') default '0' not null,
* torrent_pass char(32) not null,
* rawup bigint unsigned not null,
* rawdl bigint unsigned not null,
* DownMultiplier float default 1 not null,
* UpMultiplier float default 1 not null,
* DisableDownload tinyint(1) default 0 not null,
* TrackerHide tinyint(1) default 0 not null
* );
*/
$table = $this->table("users_main");
$table
->addColumn("rawup", "biginteger", ["null" => false, "after" => "downloaded"])
->addColumn("rawdl", "biginteger", ["null" => false, "after" => "rawup"])

->addColumn("downMultiplier", "float", ["default" => 1, "null" => false, "after" => "rawdl"])
->addColumn("upMultiplier", "float", ["default" => 1, "null" => false, "after" => "downMultiplier"])

->addColumn("disableDownload", "boolean", ["default" => false, "null" => false, "after" => "upMultiplier"])
->addColumn("trackerHide", "boolean", ["default" => false, "null" => false, "after" => "disableDownload"])

->update();
}
}