#86: Fixed more queries for PostgreSQL.

This commit is contained in:
Peter Deltchev 2016-07-09 06:44:49 -07:00
parent 7b521f5733
commit 0427658dbf
17 changed files with 234 additions and 220 deletions

View file

@ -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->tracks()->attach($this->_track, ['position' => $songIndex]);
$this->_playlist->touch(); $this->_playlist->touch();

View file

@ -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) ->belongsToMany(Track::class)
->withPivot('position') ->withPivot('position')
->withTimestamps(); ->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() public function trackFiles()

View file

@ -39,7 +39,7 @@ class ShowSong extends Model
public function trackCountRelation() { public function trackCountRelation() {
return $this->belongsToMany(Track::class) return $this->belongsToMany(Track::class)
->select(['show_song_id', DB::raw('count(*) as track_count')]) ->select(['show_song_id', DB::raw('count(*) as track_count')])
->groupBy('show_song_id'); ->groupBy('show_song_id', 'track_id');
} }
public function tracks(){ public function tracks(){

View file

@ -30,7 +30,9 @@
}, },
"autoload": { "autoload": {
"classmap": [ "classmap": [
"database", "database/factories",
"database/migrations",
"database/seeds",
"app/Library" "app/Library"
], ],
"psr-4": { "psr-4": {

View file

@ -17,8 +17,8 @@ class CreateActivitiesTable extends Migration {
$table->bigInteger('id', true)->unsigned(); $table->bigInteger('id', true)->unsigned();
$table->dateTime('created_at')->index(); $table->dateTime('created_at')->index();
$table->integer('user_id')->unsigned(); $table->integer('user_id')->unsigned();
$table->boolean('activity_type'); $table->unsignedTinyInteger('activity_type');
$table->boolean('resource_type'); $table->unsignedTinyInteger('resource_type');
$table->integer('resource_id')->unsigned(); $table->integer('resource_id')->unsigned();
}); });
} }

View file

@ -3,7 +3,12 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; 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. * Run the migrations.

View file

@ -3,7 +3,12 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; 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. * Run the migrations.
@ -20,7 +25,7 @@ class CreateImagesTable extends Migration {
$table->string('extension', 32); $table->string('extension', 32);
$table->integer('size'); $table->integer('size');
$table->string('hash', 32)->index(); $table->string('hash', 32)->index();
$table->integer('uploaded_by')->unsigned()->index('images_uploaded_by_foreign'); $table->unsignedInteger('uploaded_by')->index();
$table->timestamps(); $table->timestamps();
}); });
} }

View file

@ -21,6 +21,42 @@ class CreateLicensesTable extends Migration {
$table->boolean('open_distribution'); $table->boolean('open_distribution');
$table->boolean('remix'); $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
]);
} }

View file

@ -3,7 +3,12 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; 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. * Run the migrations.

View file

@ -3,7 +3,13 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; 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. * Run the migrations.

View file

@ -17,8 +17,12 @@ class CreateRolesTable extends Migration {
$table->increments('id'); $table->increments('id');
$table->string('name'); $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. * Reverse the migrations.
@ -29,5 +33,4 @@ class CreateRolesTable extends Migration {
{ {
Schema::drop('roles'); Schema::drop('roles');
} }
} }

View file

@ -3,7 +3,12 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; 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. * Run the migrations.

View file

@ -18,6 +18,42 @@ class CreateTrackTypesTable extends Migration {
$table->string('title'); $table->string('title');
$table->string('editor_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'
]);
} }

View file

@ -3,7 +3,12 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; 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. * Run the migrations.

View file

@ -3,7 +3,12 @@
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint; 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. * Run the migrations.

View file

@ -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();
}
}

View file

@ -22,25 +22,12 @@ use Illuminate\Database\Seeder;
class ShowSongTableSeeder extends Seeder class ShowSongTableSeeder extends Seeder
{ {
/** private $showSongs = [
* 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', 'title' => 'My Little Pony Theme Song',
'slug' => 'my-little-pony-theme-song', 'slug' => 'my-little-pony-theme-song',
'lyrics' => 'lyrics' =>
"[Backup singer] "[Backup singer]
My Little Pony, My Little Pony My Little Pony, My Little Pony
Ahh, ahh, ahh, ahhh... Ahh, ahh, ahh, ahhh...
@ -76,7 +63,7 @@ Do you know you're all my very best friends?"
'title' => 'Laughter Song (Giggle at the Ghostly)', 'title' => 'Laughter Song (Giggle at the Ghostly)',
'slug' => 'laughter-song', 'slug' => 'laughter-song',
'lyrics' => 'lyrics' =>
"[Pinkie Pie] "[Pinkie Pie]
When I was a little filly and the sun was going down... When I was a little filly and the sun was going down...
Twilight Sparkle: Tell me she's not... Twilight Sparkle: Tell me she's not...
@ -121,7 +108,7 @@ Laaaaaaauuugh!"
'title' => 'Winter Wrap-Up', 'title' => 'Winter Wrap-Up',
'slug' => 'winter-wrap-up', 'slug' => 'winter-wrap-up',
'lyrics' => 'lyrics' =>
"[Rainbow Dash] "[Rainbow Dash]
Three months of winter coolness Three months of winter coolness
And awesome holidays And awesome holidays
@ -261,7 +248,7 @@ Winter Wrap Up! Winter Wrap Up!
'title' => 'EQG - Helping Twilight Win The Crown', 'title' => 'EQG - Helping Twilight Win The Crown',
'slug' => 'helping-twilight-win-the-crown', 'slug' => 'helping-twilight-win-the-crown',
'lyrics' => 'lyrics' =>
"[Pinkie Pie, Rainbow Dash, Applejack, Fluttershy, Rarity] "[Pinkie Pie, Rainbow Dash, Applejack, Fluttershy, Rarity]
Hey! Hey! Everybody! Hey! Hey! Everybody!
We've got something to say. We've got something to say.
We may seem as different, We may seem as different,
@ -355,7 +342,27 @@ Stomp your hooves, turn around.
Canterlot Wondercolts Canterlot Wondercolts
Help her win the crown..." 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);
} }
} }
} }