mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-24 22:18:00 +01:00
#86: Fixed more queries for PostgreSQL.
This commit is contained in:
parent
7b521f5733
commit
0427658dbf
17 changed files with 234 additions and 220 deletions
|
@ -67,7 +67,7 @@ class AddTrackToPlaylistCommand extends CommandBase
|
|||
}
|
||||
|
||||
|
||||
$songIndex = $this->_playlist->tracks()->count() + 1;
|
||||
$songIndex = $this->_playlist->trackCount() + 1;
|
||||
$this->_playlist->tracks()->attach($this->_track, ['position' => $songIndex]);
|
||||
$this->_playlist->touch();
|
||||
|
||||
|
|
|
@ -198,13 +198,23 @@ class Playlist extends Model implements Searchable, Commentable, Favouritable
|
|||
];
|
||||
}
|
||||
|
||||
public function tracks()
|
||||
public function tracks(bool $ordered = true)
|
||||
{
|
||||
return $this
|
||||
$query = $this
|
||||
->belongsToMany(Track::class)
|
||||
->withPivot('position')
|
||||
->withTimestamps();
|
||||
//->orderBy('position', 'asc');
|
||||
|
||||
if ($ordered) {
|
||||
$query = $query->orderBy('position', 'asc');
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function trackCount():int
|
||||
{
|
||||
return $this->tracks(false)->count();
|
||||
}
|
||||
|
||||
public function trackFiles()
|
||||
|
|
|
@ -39,7 +39,7 @@ class ShowSong extends Model
|
|||
public function trackCountRelation() {
|
||||
return $this->belongsToMany(Track::class)
|
||||
->select(['show_song_id', DB::raw('count(*) as track_count')])
|
||||
->groupBy('show_song_id');
|
||||
->groupBy('show_song_id', 'track_id');
|
||||
}
|
||||
|
||||
public function tracks(){
|
||||
|
|
|
@ -30,7 +30,9 @@
|
|||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"database",
|
||||
"database/factories",
|
||||
"database/migrations",
|
||||
"database/seeds",
|
||||
"app/Library"
|
||||
],
|
||||
"psr-4": {
|
||||
|
|
|
@ -17,8 +17,8 @@ class CreateActivitiesTable extends Migration {
|
|||
$table->bigInteger('id', true)->unsigned();
|
||||
$table->dateTime('created_at')->index();
|
||||
$table->integer('user_id')->unsigned();
|
||||
$table->boolean('activity_type');
|
||||
$table->boolean('resource_type');
|
||||
$table->unsignedTinyInteger('activity_type');
|
||||
$table->unsignedTinyInteger('resource_type');
|
||||
$table->integer('resource_id')->unsigned();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateFailedJobsTable extends Migration {
|
||||
/**
|
||||
* Class CreateFailedJobsTable2
|
||||
*
|
||||
* This is the PostgreSQL version of CreateFailedJobsTable.
|
||||
*/
|
||||
class CreateFailedJobsTable2 extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
|
@ -3,7 +3,12 @@
|
|||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateImagesTable extends Migration {
|
||||
/**
|
||||
* Class CreateImagesTable2
|
||||
*
|
||||
* This is the PostgreSQL version of CreateImagesTable.
|
||||
*/
|
||||
class CreateImagesTable2 extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
|
@ -20,7 +25,7 @@ class CreateImagesTable extends Migration {
|
|||
$table->string('extension', 32);
|
||||
$table->integer('size');
|
||||
$table->string('hash', 32)->index();
|
||||
$table->integer('uploaded_by')->unsigned()->index('images_uploaded_by_foreign');
|
||||
$table->unsignedInteger('uploaded_by')->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
|
@ -5,33 +5,69 @@ use Illuminate\Database\Schema\Blueprint;
|
|||
|
||||
class CreateLicensesTable extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('licenses', function(Blueprint $table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->string('title', 100);
|
||||
$table->text('description', 65535);
|
||||
$table->boolean('affiliate_distribution');
|
||||
$table->boolean('open_distribution');
|
||||
$table->boolean('remix');
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('licenses', function(Blueprint $table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->string('title', 100);
|
||||
$table->text('description', 65535);
|
||||
$table->boolean('affiliate_distribution');
|
||||
$table->boolean('open_distribution');
|
||||
$table->boolean('remix');
|
||||
});
|
||||
|
||||
DB::table('licenses')->insert([
|
||||
'id' => 1,
|
||||
'title' => 'Personal',
|
||||
'description' => 'Only you and Pony.fm are allowed to distribute and broadcast the track.',
|
||||
'affiliate_distribution' => 0,
|
||||
'open_distribution' => 0,
|
||||
'remix' => 0
|
||||
]);
|
||||
|
||||
DB::table('licenses')->insert([
|
||||
'id' => 2,
|
||||
'title' => 'Broadcast',
|
||||
'description' => 'You, Pony.fm, and its affiliates may distribute and broadcast the track.',
|
||||
'affiliate_distribution' => 1,
|
||||
'open_distribution' => 0,
|
||||
'remix' => 0
|
||||
]);
|
||||
|
||||
DB::table('licenses')->insert([
|
||||
'id' => 3,
|
||||
'title' => 'Open',
|
||||
'description' => 'Anyone is permitted to broadcast and distribute the song in its original form, with attribution to you.',
|
||||
'affiliate_distribution' => 1,
|
||||
'open_distribution' => 1,
|
||||
'remix' => 0
|
||||
]);
|
||||
|
||||
DB::table('licenses')->insert([
|
||||
'id' => 4,
|
||||
'title' => 'Remix',
|
||||
'description' => 'Anyone is permitted to broadcast and distribute the song in any form, or create derivative works based on it for any purpose, with attribution to you.',
|
||||
'affiliate_distribution' => 1,
|
||||
'open_distribution' => 1,
|
||||
'remix' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('licenses');
|
||||
}
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('licenses');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateNewsTable extends Migration {
|
||||
/**
|
||||
* Class CreateNewsTable2
|
||||
*
|
||||
* This is the PostgreSQL version of CreateNewsTable.
|
||||
*/
|
||||
class CreateNewsTable2 extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
|
@ -3,7 +3,13 @@
|
|||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateRevisionsTable extends Migration {
|
||||
|
||||
/**
|
||||
* Class CreateRevisionsTable2
|
||||
*
|
||||
* This is the PostgreSQL version of CreateRevisionsTable.
|
||||
*/
|
||||
class CreateRevisionsTable2 extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
|
@ -5,29 +5,32 @@ use Illuminate\Database\Schema\Blueprint;
|
|||
|
||||
class CreateRolesTable extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('roles', function(Blueprint $table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('roles', function(Blueprint $table)
|
||||
{
|
||||
$table->increments('id');
|
||||
$table->string('name');
|
||||
});
|
||||
|
||||
DB::table('roles')->insert(['name' => 'super_admin']);
|
||||
DB::table('roles')->insert(['name' => 'admin']);
|
||||
DB::table('roles')->insert(['name' => 'moderator']);
|
||||
DB::table('roles')->insert(['name' => 'user']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('roles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('roles');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateTrackFilesTable extends Migration {
|
||||
/**
|
||||
* Class CreateTrackFilesTable2
|
||||
*
|
||||
* This is the PostgreSQL version of CreateTrackFilesTable.
|
||||
*/
|
||||
class CreateTrackFilesTable2 extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
|
@ -18,6 +18,42 @@ class CreateTrackTypesTable extends Migration {
|
|||
$table->string('title');
|
||||
$table->string('editor_title');
|
||||
});
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 1,
|
||||
'title' => 'Original Song',
|
||||
'editor_title' => 'an original song'
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 2,
|
||||
'title' => 'Official Song Remix',
|
||||
'editor_title' => 'a remix of an official song'
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 3,
|
||||
'title' => 'Fan Song Remix',
|
||||
'editor_title' => 'a remix of a fan song'
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 4,
|
||||
'title' => 'Ponified Song',
|
||||
'editor_title' => 'a non-pony song, turned pony'
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 5,
|
||||
'title' => 'Official Show Audio Remix',
|
||||
'editor_title' => 'a remix of official show audio'
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 6,
|
||||
'title' => 'Unclassified',
|
||||
'editor_title' => 'an unclassified track'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,12 @@
|
|||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateTracksTable extends Migration {
|
||||
/**
|
||||
* Class CreateTracksTable2
|
||||
*
|
||||
* This is the PostgreSQL version of CreateTracksTable.
|
||||
*/
|
||||
class CreateTracksTable2 extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
|
@ -3,7 +3,12 @@
|
|||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateUsersTable extends Migration {
|
||||
/**
|
||||
* Class CreateUsersTable2
|
||||
*
|
||||
* This is the PostgreSQL version of CreateUsersTable.
|
||||
*/
|
||||
class CreateUsersTable2 extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
|
@ -1,116 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Pony.fm - A community for pony fan music.
|
||||
* Copyright (C) 2016 Peter Deltchev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class InsertStaticData extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::table('licenses')->insert([
|
||||
'id' => 1,
|
||||
'title' => 'Personal',
|
||||
'description' => 'Only you and Pony.fm are allowed to distribute and broadcast the track.',
|
||||
'affiliate_distribution' => 0,
|
||||
'open_distribution' => 0,
|
||||
'remix' => 0
|
||||
]);
|
||||
|
||||
DB::table('licenses')->insert([
|
||||
'id' => 2,
|
||||
'title' => 'Broadcast',
|
||||
'description' => 'You, Pony.fm, and its affiliates may distribute and broadcast the track.',
|
||||
'affiliate_distribution' => 1,
|
||||
'open_distribution' => 0,
|
||||
'remix' => 0
|
||||
]);
|
||||
|
||||
DB::table('licenses')->insert([
|
||||
'id' => 3,
|
||||
'title' => 'Open',
|
||||
'description' => 'Anyone is permitted to broadcast and distribute the song in its original form, with attribution to you.',
|
||||
'affiliate_distribution' => 1,
|
||||
'open_distribution' => 1,
|
||||
'remix' => 0
|
||||
]);
|
||||
|
||||
DB::table('licenses')->insert([
|
||||
'id' => 4,
|
||||
'title' => 'Remix',
|
||||
'description' => 'Anyone is permitted to broadcast and distribute the song in any form, or create derivative works based on it for any purpose, with attribution to you.',
|
||||
'affiliate_distribution' => 1,
|
||||
'open_distribution' => 1,
|
||||
'remix' => 1
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 1,
|
||||
'title' => 'Original Song',
|
||||
'editor_title' => 'an original song'
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 2,
|
||||
'title' => 'Official Song Remix',
|
||||
'editor_title' => 'a remix of an official song'
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 3,
|
||||
'title' => 'Fan Song Remix',
|
||||
'editor_title' => 'a remix of a fan song'
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 4,
|
||||
'title' => 'Ponified Song',
|
||||
'editor_title' => 'a non-pony song, turned pony'
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 5,
|
||||
'title' => 'Official Show Audio Remix',
|
||||
'editor_title' => 'a remix of official show audio'
|
||||
]);
|
||||
|
||||
DB::table('track_types')->insert([
|
||||
'id' => 6,
|
||||
'title' => 'Unclassified',
|
||||
'editor_title' => 'an unclassified track'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
DB::table('licenses')->whereIn('id', [1, 2, 3, 4])->delete();
|
||||
DB::table('track_types')->whereIn('id', [1, 2, 3, 4, 5, 6])->delete();
|
||||
}
|
||||
}
|
|
@ -22,25 +22,12 @@ use Illuminate\Database\Seeder;
|
|||
|
||||
class ShowSongTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// This table only needs to be filled once.
|
||||
//
|
||||
// Song lyrics used are (C) Hasbro and
|
||||
// sourced from http://mlp.wikia.com/wiki/Songs
|
||||
if (DB::table('show_songs')->count() === 0) {
|
||||
DB::table('show_songs')->insert(
|
||||
[
|
||||
[
|
||||
'title' => 'My Little Pony Theme Song',
|
||||
'slug' => 'my-little-pony-theme-song',
|
||||
'lyrics' =>
|
||||
"[Backup singer]
|
||||
private $showSongs = [
|
||||
[
|
||||
'title' => 'My Little Pony Theme Song',
|
||||
'slug' => 'my-little-pony-theme-song',
|
||||
'lyrics' =>
|
||||
"[Backup singer]
|
||||
My Little Pony, My Little Pony
|
||||
Ahh, ahh, ahh, ahhh...
|
||||
|
||||
|
@ -71,12 +58,12 @@ And magic makes it all complete
|
|||
You have my little ponies
|
||||
Do you know you're all my very best friends?"
|
||||
|
||||
],
|
||||
[
|
||||
'title' => 'Laughter Song (Giggle at the Ghostly)',
|
||||
'slug' => 'laughter-song',
|
||||
'lyrics' =>
|
||||
"[Pinkie Pie]
|
||||
],
|
||||
[
|
||||
'title' => 'Laughter Song (Giggle at the Ghostly)',
|
||||
'slug' => 'laughter-song',
|
||||
'lyrics' =>
|
||||
"[Pinkie Pie]
|
||||
When I was a little filly and the sun was going down...
|
||||
|
||||
Twilight Sparkle: Tell me she's not...
|
||||
|
@ -116,12 +103,12 @@ And tell that big dumb scary face to take a hike and leave you alone and if he t
|
|||
|
||||
Laaaaaaauuugh!"
|
||||
|
||||
],
|
||||
[
|
||||
'title' => 'Winter Wrap-Up',
|
||||
'slug' => 'winter-wrap-up',
|
||||
'lyrics' =>
|
||||
"[Rainbow Dash]
|
||||
],
|
||||
[
|
||||
'title' => 'Winter Wrap-Up',
|
||||
'slug' => 'winter-wrap-up',
|
||||
'lyrics' =>
|
||||
"[Rainbow Dash]
|
||||
Three months of winter coolness
|
||||
And awesome holidays
|
||||
|
||||
|
@ -256,12 +243,12 @@ Winter Wrap Up! Winter Wrap Up!
|
|||
'Cause tomorrow spring is here
|
||||
'Cause tomorrow spring is here
|
||||
'Cause tomorrow spring is here!"
|
||||
],
|
||||
[
|
||||
'title' => 'EQG - Helping Twilight Win The Crown',
|
||||
'slug' => 'helping-twilight-win-the-crown',
|
||||
'lyrics' =>
|
||||
"[Pinkie Pie, Rainbow Dash, Applejack, Fluttershy, Rarity]
|
||||
],
|
||||
[
|
||||
'title' => 'EQG - Helping Twilight Win The Crown',
|
||||
'slug' => 'helping-twilight-win-the-crown',
|
||||
'lyrics' =>
|
||||
"[Pinkie Pie, Rainbow Dash, Applejack, Fluttershy, Rarity]
|
||||
Hey! Hey! Everybody!
|
||||
We've got something to say.
|
||||
We may seem as different,
|
||||
|
@ -354,8 +341,28 @@ Jump up, make a sound. Hey!
|
|||
Stomp your hooves, turn around.
|
||||
Canterlot Wondercolts
|
||||
Help her win the crown..."
|
||||
]
|
||||
]);
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// This table only needs to be filled once.
|
||||
//
|
||||
// Song lyrics used are (C) Hasbro and
|
||||
// sourced from http://mlp.wikia.com/wiki/Songs
|
||||
if (DB::table('show_songs')->count() === 0) {
|
||||
$now = \Carbon\Carbon::now();
|
||||
$showSongs = array_map(function(array $item) use ($now) {
|
||||
$item['created_at'] = $now;
|
||||
$item['updated_at'] = $now;
|
||||
return $item;
|
||||
}, $this->showSongs);
|
||||
DB::table('show_songs')->insert($showSongs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue