diff --git a/.env.example b/.env.example index 39a054fe0..33c07de71 100644 --- a/.env.example +++ b/.env.example @@ -12,7 +12,7 @@ LOG_LEVEL=debug # You can change this to info, warning or error for production u L5_SWAGGER_CONST_HOST=http://localhost:8000 # Change this according to your database configuration -# To use SQLite, have a look here: https://laravel.com/docs/8.x/database#sqlite-configuration1 +# To use SQLite, have a look here: https://laravel.com/docs/10.x/database#sqlite-configuration DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 @@ -26,7 +26,7 @@ QUEUE_CONNECTION=sync SESSION_LIFETIME=120 # To be able to send mails and debug them, you can set up a mailtrap.io account and enter your credentials here -# You can also take a look here for other configuration possibilities: https://laravel.com/docs/8.x/mail#configuration +# You can also take a look here for other configuration possibilities: https://laravel.com/docs/10.x/mail#configuration MAIL_DRIVER=smtp MAIL_HOST=smtp.mailtrap.io MAIL_PORT=2525 diff --git a/app/Http/Controllers/API/v1/StationController.php b/app/Http/Controllers/API/v1/StationController.php index 73dccc376..12c72c923 100644 --- a/app/Http/Controllers/API/v1/StationController.php +++ b/app/Http/Controllers/API/v1/StationController.php @@ -99,8 +99,8 @@ public function merge(int $oldStationId, int $newStationId): StationResource { Checkin::where('origin', $oldStation->ibnr)->update(['origin' => $newStation->ibnr]); Checkin::where('destination', $oldStation->ibnr)->update(['destination' => $newStation->ibnr]); Stopover::where('train_station_id', $oldStation->id)->update(['train_station_id' => $newStation->id]); - Trip::where('origin', $oldStation->ibnr)->update(['origin' => $newStation->ibnr]); - Trip::where('destination', $oldStation->ibnr)->update(['destination' => $newStation->ibnr]); + Trip::where('origin_id', $oldStation->id)->update(['origin_id' => $newStation->id]); + Trip::where('destination_id', $oldStation->id)->update(['destination_id' => $newStation->id]); Event::where('station_id', $oldStation->id)->update(['station_id' => $newStation->id]); EventSuggestion::where('station_id', $oldStation->id)->update(['station_id' => $newStation->id]); diff --git a/database/factories/TripFactory.php b/database/factories/TripFactory.php index ca98f5100..db3087c5d 100644 --- a/database/factories/TripFactory.php +++ b/database/factories/TripFactory.php @@ -6,9 +6,9 @@ use App\Enum\TripSource; use App\Http\Controllers\TransportController; use App\Models\HafasOperator; -use App\Models\Trip; use App\Models\Station; use App\Models\Stopover; +use App\Models\Trip; use Illuminate\Database\Eloquent\Factories\Factory; class TripFactory extends Factory @@ -29,8 +29,8 @@ public function definition(): array { 'linename' => $this->faker->bothify('?? ##'), 'journey_number' => $this->faker->numberBetween(10000, 99999), 'operator_id' => HafasOperator::factory()->create()->id, - 'origin' => $origin->ibnr, - 'destination' => $destination->ibnr, + 'origin_id' => $origin->id, + 'destination_id' => $destination->id, 'polyline_id' => null, //Will be set in the configure function 'departure' => now()->subMinutes(15)->format('c'), 'arrival' => now()->addMinutes(80)->format('c'), diff --git a/database/migrations/2023_11_21_000002_add_default_permissions.php b/database/migrations/2023_11_21_000002_add_default_permissions.php index 4cbbf739f..996033e93 100644 --- a/database/migrations/2023_11_21_000002_add_default_permissions.php +++ b/database/migrations/2023_11_21_000002_add_default_permissions.php @@ -1,61 +1,10 @@ 'admin']); - $roleEventModerator = Role::create(['name' => 'event-moderator']); //for accepting/denying events - Role::create(['name' => 'open-beta']); //for experimental features that can be enabled by users - Role::create(['name' => 'closed-beta']); //for experimental features that can be only enabled by admins for specific users - - $permissionViewBackend = Permission::create(['name' => 'view-backend']); - - $permissionViewEvents = Permission::create(['name' => 'view-events']); - $permissionAcceptEvents = Permission::create(['name' => 'accept-events']); - $permissionDenyEvents = Permission::create(['name' => 'deny-events']); - $permissionCreateEvents = Permission::create(['name' => 'create-events']); - $permissionUpdateEvents = Permission::create(['name' => 'update-events']); - $permissionDeleteEvents = Permission::create(['name' => 'delete-events']); - - $roleAdmin->givePermissionTo($permissionViewBackend); - $roleAdmin->givePermissionTo($permissionViewEvents); - $roleAdmin->givePermissionTo($permissionAcceptEvents); - $roleAdmin->givePermissionTo($permissionDenyEvents); - $roleAdmin->givePermissionTo($permissionCreateEvents); - $roleAdmin->givePermissionTo($permissionUpdateEvents); - $roleAdmin->givePermissionTo($permissionDeleteEvents); - - $roleEventModerator->givePermissionTo($permissionViewBackend); - $roleEventModerator->givePermissionTo($permissionViewEvents); - $roleEventModerator->givePermissionTo($permissionAcceptEvents); - $roleEventModerator->givePermissionTo($permissionDenyEvents); - $roleEventModerator->givePermissionTo($permissionUpdateEvents); - - $oldAdmins = User::where('role', 10)->get(); - foreach ($oldAdmins as $oldAdmin) { - $oldAdmin->assignRole('admin'); - } - - $experimentalUsers = User::where('experimental', true)->get(); - foreach ($experimentalUsers as $experimentalUser) { - $experimentalUser->assignRole('open-beta'); - } - } - - public function down(): void { - $admins = User::role('admin')->get(); - foreach ($admins as $admin) { - $admin->update(['role' => 10]); - } - - Role::where('name', 'admin')->delete(); - Role::where('name', 'event-moderator')->delete(); - Role::where('name', 'open-beta')->delete(); - Role::where('name', 'closed-beta')->delete(); + // empty now - replaced by PermissionSeeder } }; diff --git a/database/migrations/2023_12_17_000003_add_event_history_permission.php b/database/migrations/2023_12_17_000003_add_event_history_permission.php index cfcb608eb..72819db27 100644 --- a/database/migrations/2023_12_17_000003_add_event_history_permission.php +++ b/database/migrations/2023_12_17_000003_add_event_history_permission.php @@ -7,11 +7,6 @@ return new class extends Migration { public function up(): void { - $permission = Permission::create(['name' => 'view event history']); - Role::findByName('admin')->givePermissionTo($permission); - } - - public function down(): void { - Permission::findByName('view event history')->delete(); + // empty now - replaced by PermissionSeeder } }; diff --git a/database/migrations/2024_01_29_000000_add_station_permissions.php b/database/migrations/2024_01_29_000000_add_station_permissions.php index f9bcfbc81..72819db27 100644 --- a/database/migrations/2024_01_29_000000_add_station_permissions.php +++ b/database/migrations/2024_01_29_000000_add_station_permissions.php @@ -7,28 +7,6 @@ return new class extends Migration { public function up(): void { - $permissionCreate = Permission::create(['name' => 'create stations']); - $permissionUpdate = Permission::create(['name' => 'update stations']); - $permissionDelete = Permission::create(['name' => 'delete stations']); - - $roleAdmin = Role::findByName('admin'); - $roleAdmin->givePermissionTo($permissionCreate); - $roleAdmin->givePermissionTo($permissionUpdate); - $roleAdmin->givePermissionTo($permissionDelete); - } - - public function down(): void { - $permissionCreate = Permission::findByName('create stations'); - $permissionUpdate = Permission::findByName('update stations'); - $permissionDelete = Permission::findByName('delete stations'); - - $roleAdmin = Role::findByName('admin'); - $roleAdmin->revokePermissionTo($permissionCreate); - $roleAdmin->revokePermissionTo($permissionUpdate); - $roleAdmin->revokePermissionTo($permissionDelete); - - $permissionCreate->delete(); - $permissionUpdate->delete(); - $permissionDelete->delete(); + // empty now - replaced by PermissionSeeder } }; diff --git a/database/migrations/2024_01_30_000000_add_activity_permissions.php b/database/migrations/2024_01_30_000000_add_activity_permissions.php index e01442bbc..72819db27 100644 --- a/database/migrations/2024_01_30_000000_add_activity_permissions.php +++ b/database/migrations/2024_01_30_000000_add_activity_permissions.php @@ -7,18 +7,6 @@ return new class extends Migration { public function up(): void { - $permission = Permission::create(['name' => 'view activity']); - - $roleAdmin = Role::findByName('admin'); - $roleAdmin->givePermissionTo($permission); - } - - public function down(): void { - $permission = Permission::findByName('view activity'); - - $roleAdmin = Role::findByName('admin'); - $roleAdmin->revokePermissionTo($permission); - - $permission->delete(); + // empty now - replaced by PermissionSeeder } }; diff --git a/database/migrations/2024_02_01_000000_add_permissions_for_manual_trips_beta.php b/database/migrations/2024_02_01_000000_add_permissions_for_manual_trips_beta.php index a26b93310..687d34524 100644 --- a/database/migrations/2024_02_01_000000_add_permissions_for_manual_trips_beta.php +++ b/database/migrations/2024_02_01_000000_add_permissions_for_manual_trips_beta.php @@ -1,25 +1,11 @@ 'create-manual-trip']); - - Role::findByName('admin')->givePermissionTo($permission); - Role::findByName('closed-beta')->givePermissionTo($permission); - } - - public function down(): void { - $permission = Permission::findByName('create-manual-trip'); - - Role::findByName('admin')->revokePermissionTo($permission); - Role::findByName('closed-beta')->revokePermissionTo($permission); - - $permission->delete(); + // empty now - replaced by PermissionSeeder } }; diff --git a/database/migrations/2024_03_11_000000_add_origin_and_destination_id_to_trips.php b/database/migrations/2024_03_11_000000_add_origin_and_destination_id_to_trips.php index e719a68bb..9c87b2cef 100644 --- a/database/migrations/2024_03_11_000000_add_origin_and_destination_id_to_trips.php +++ b/database/migrations/2024_03_11_000000_add_origin_and_destination_id_to_trips.php @@ -26,6 +26,19 @@ public function up(): void { 'destination_id' => DB::raw('(SELECT id FROM train_stations WHERE ibnr = hafas_trips.destination)'), ]); + if (config('database.default') === 'sqlite') { + //warn the user that they need to manually drop the columns + echo PHP_EOL . PHP_EOL; + echo "\033[41m"; //console background color red + echo '--- WARNING ---' . PHP_EOL; + echo 'SQLite doesn\'t support dropping foreign keys' . PHP_EOL; + echo 'Please drop the columns "origin" and "destination" manually from the "hafas_trips" table.' . PHP_EOL; + echo '--- WARNING ---'; + echo "\033[0m"; //reset console color + echo PHP_EOL . PHP_EOL; + return; + } + Schema::table('hafas_trips', static function(Blueprint $table) { $table->dropForeign(['origin']); $table->dropColumn('origin'); diff --git a/database/schema/sqlite-schema.sql b/database/schema/sqlite-schema.sql new file mode 100644 index 000000000..f8d84db2b --- /dev/null +++ b/database/schema/sqlite-schema.sql @@ -0,0 +1,285 @@ +CREATE TABLE IF NOT EXISTS "migrations" ("id" integer primary key autoincrement not null, "migration" varchar not null, "batch" integer not null); +CREATE TABLE IF NOT EXISTS "password_resets" ("email" varchar not null, "token" varchar not null, "created_at" datetime); +CREATE INDEX "password_resets_email_index" on "password_resets" ("email"); +CREATE TABLE IF NOT EXISTS "oauth_refresh_tokens" ("id" varchar not null, "access_token_id" varchar not null, "revoked" tinyint(1) not null, "expires_at" datetime, primary key ("id")); +CREATE INDEX "oauth_refresh_tokens_access_token_id_index" on "oauth_refresh_tokens" ("access_token_id"); +CREATE TABLE IF NOT EXISTS "mastodon_servers" ("id" integer primary key autoincrement not null, "domain" varchar not null, "client_id" varchar not null, "client_secret" varchar not null, "created_at" datetime, "updated_at" datetime); +CREATE UNIQUE INDEX "mastodon_servers_domain_unique" on "mastodon_servers" ("domain"); +CREATE TABLE IF NOT EXISTS "sessions" ("id" varchar not null, "user_id" integer, "ip_address" varchar, "user_agent" text, "payload" text not null, "last_activity" integer not null); +CREATE TABLE IF NOT EXISTS "privacy_agreements" ("id" integer primary key autoincrement not null, "body_md_de" text not null, "body_md_en" text not null, "valid_at" datetime not null, "created_at" datetime, "updated_at" datetime); +CREATE TABLE IF NOT EXISTS "poly_lines" ("id" integer primary key autoincrement not null, "hash" varchar not null, "polyline" text not null, "created_at" datetime, "updated_at" datetime, "source" varchar check ("source" in ('hafas', 'brouter')) not null default 'hafas', "parent_id" integer); +CREATE TABLE IF NOT EXISTS "notifications" ("id" varchar not null, "type" varchar not null, "notifiable_type" varchar not null, "notifiable_id" integer not null, "data" text not null, "read_at" datetime, "created_at" datetime, "updated_at" datetime, primary key ("id")); +CREATE INDEX "notifications_notifiable_type_notifiable_id_index" on "notifications" ("notifiable_type", "notifiable_id"); +CREATE TABLE train_stations (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ibnr BIGINT UNSIGNED NOT NULL, name VARCHAR(255) NOT NULL, latitude NUMERIC(9, 6) NOT NULL, longitude NUMERIC(9, 6) NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, "rilIdentifier" varchar, "time_offset" integer, "shift_time" tinyint(1), "wikidata_id" varchar, "ifopt_e" integer, "ifopt_d" integer, "ifopt_c" integer, "ifopt_b" integer, "ifopt_a" varchar); +CREATE UNIQUE INDEX train_stations_ibnr_unique ON train_stations (ibnr); +CREATE TABLE follows (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id BIGINT UNSIGNED NOT NULL, follow_id BIGINT UNSIGNED NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL); +CREATE INDEX "poly_lines_hash_index" on "poly_lines" ("hash"); +CREATE TABLE likes (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id BIGINT UNSIGNED NOT NULL, status_id BIGINT UNSIGNED NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL); +CREATE UNIQUE INDEX "likes_user_id_status_id_unique" on "likes" ("user_id", "status_id"); +CREATE TABLE IF NOT EXISTS "train_stopovers" ("id" integer primary key autoincrement not null, "trip_id" varchar not null, "train_station_id" integer not null, "arrival_planned" datetime, "arrival_real" datetime, "arrival_platform_planned" varchar, "arrival_platform_real" varchar, "departure_planned" datetime, "departure_real" datetime, "departure_platform_planned" varchar, "departure_platform_real" varchar, "created_at" datetime, "updated_at" datetime, "cancelled" tinyint(1) not null default '0', foreign key("trip_id") references "hafas_trips"("trip_id") on delete cascade, foreign key("train_station_id") references "train_stations"("id") on update cascade); +CREATE UNIQUE INDEX "poly_lines_hash_unique" on "poly_lines" ("hash"); +CREATE TABLE IF NOT EXISTS "ics_tokens" ("id" integer primary key autoincrement not null, "user_id" integer not null, "token" varchar not null, "created_at" datetime, "updated_at" datetime, "name" varchar, "last_accessed" datetime, foreign key("user_id") references "users"("id") on delete cascade); +CREATE UNIQUE INDEX "ics_tokens_token_unique" on "ics_tokens" ("token"); +CREATE TABLE IF NOT EXISTS "hafas_operators" ("id" integer primary key autoincrement not null, "hafas_id" varchar not null, "name" varchar not null, "created_at" datetime, "updated_at" datetime); +CREATE UNIQUE INDEX "hafas_operators_hafas_id_unique" on "hafas_operators" ("hafas_id"); +CREATE TABLE IF NOT EXISTS "follow_requests" ("id" integer primary key autoincrement not null, "user_id" integer not null, "follow_id" integer not null, "created_at" datetime, "updated_at" datetime, foreign key("user_id") references "users"("id") on delete cascade, foreign key("follow_id") references "users"("id") on delete cascade); +CREATE UNIQUE INDEX "follow_requests_user_id_follow_id_unique" on "follow_requests" ("user_id", "follow_id"); +CREATE TABLE IF NOT EXISTS "user_mutes" ("id" integer primary key autoincrement not null, "user_id" integer not null, "muted_id" integer not null, "created_at" datetime, "updated_at" datetime, foreign key("user_id") references "users"("id") on delete cascade, foreign key("muted_id") references "users"("id") on delete cascade); +CREATE UNIQUE INDEX "user_mutes_user_id_muted_id_unique" on "user_mutes" ("user_id", "muted_id"); +CREATE INDEX "sessions_user_id_index" on "sessions" ("user_id"); +CREATE INDEX "sessions_last_activity_index" on "sessions" ("last_activity"); +CREATE INDEX "train_stopovers_arrival_planned_arrival_real_index" on "train_stopovers" ("arrival_planned", "arrival_real"); +CREATE UNIQUE INDEX "train_stopovers_trip_id_train_station_id_unique" on "train_stopovers" ("trip_id", "train_station_id", "arrival_planned", "departure_planned"); +CREATE TABLE IF NOT EXISTS "jobs" ("id" integer primary key autoincrement not null, "queue" varchar not null, "payload" text not null, "attempts" integer not null, "reserved_at" integer, "available_at" integer not null, "created_at" integer not null); +CREATE INDEX "jobs_queue_index" on "jobs" ("queue"); +CREATE INDEX "train_stopovers_departure_planned_index" on "train_stopovers" ("departure_planned"); +CREATE INDEX "train_stopovers_departure_real_index" on "train_stopovers" ("departure_real"); +CREATE INDEX "train_stopovers_arrival_planned_index" on "train_stopovers" ("arrival_planned"); +CREATE INDEX "train_stopovers_arrival_real_index" on "train_stopovers" ("arrival_real"); +CREATE TABLE IF NOT EXISTS "cache" ("key" varchar not null, "value" text not null, "expiration" integer not null, primary key ("key")); +CREATE TABLE IF NOT EXISTS "cache_locks" ("key" varchar not null, "owner" varchar not null, "expiration" integer not null, primary key ("key")); +CREATE UNIQUE INDEX "stopovers_station_arrival" on "train_stopovers" ("trip_id", "train_station_id", "arrival_planned"); +CREATE UNIQUE INDEX "stopovers_station_departure" on "train_stopovers" ("trip_id", "train_station_id", "departure_planned"); +CREATE TABLE IF NOT EXISTS "status_tags" ("id" integer primary key autoincrement not null, "status_id" integer not null, "key" varchar not null, "value" varchar not null, "visibility" integer not null default '3', "created_at" datetime, "updated_at" datetime, foreign key("status_id") references "statuses"("id") on delete cascade); +CREATE UNIQUE INDEX "status_tags_status_id_key_unique" on "status_tags" ("status_id", "key"); +CREATE TABLE IF NOT EXISTS "user_blocks" ("id" integer primary key autoincrement not null, "user_id" integer not null, "blocked_id" integer not null, "created_at" datetime, "updated_at" datetime, foreign key("user_id") references "users"("id") on delete cascade, foreign key("blocked_id") references "users"("id") on delete cascade); +CREATE UNIQUE INDEX "user_blocks_user_id_blocked_id_unique" on "user_blocks" ("user_id", "blocked_id"); +CREATE TABLE queue_monitor (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, job_id VARCHAR(255) NOT NULL COLLATE "BINARY", name VARCHAR(255) DEFAULT NULL COLLATE "BINARY", queue VARCHAR(255) DEFAULT NULL COLLATE "BINARY", started_at DATETIME DEFAULT NULL, started_at_exact VARCHAR(255) DEFAULT NULL COLLATE "BINARY", finished_at DATETIME DEFAULT NULL, finished_at_exact VARCHAR(255) DEFAULT NULL COLLATE "BINARY", attempt INTEGER DEFAULT 0 NOT NULL, progress INTEGER DEFAULT NULL, exception CLOB DEFAULT NULL COLLATE "BINARY", exception_message CLOB DEFAULT NULL COLLATE "BINARY", exception_class CLOB DEFAULT NULL COLLATE "BINARY", data CLOB DEFAULT NULL COLLATE "BINARY", status INTEGER DEFAULT 0 NOT NULL, "job_uuid" varchar, "retried" tinyint(1) not null default '0', "queued_at" datetime); +CREATE INDEX queue_monitor_started_at_index ON queue_monitor (started_at); +CREATE INDEX queue_monitor_job_id_index ON queue_monitor (job_id); +CREATE TABLE oauth_access_tokens (id VARCHAR(255) NOT NULL, user_id BIGINT UNSIGNED DEFAULT NULL, client_id BIGINT UNSIGNED NOT NULL, name VARCHAR(255) DEFAULT NULL, scopes CLOB DEFAULT NULL, revoked BOOLEAN NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, expires_at DATETIME DEFAULT NULL, PRIMARY KEY(id)); +CREATE INDEX oauth_access_tokens_user_id_index ON oauth_access_tokens (user_id); +CREATE TABLE oauth_auth_codes (id VARCHAR(255) NOT NULL, user_id BIGINT UNSIGNED NOT NULL, client_id BIGINT UNSIGNED NOT NULL, scopes CLOB DEFAULT NULL, revoked BOOLEAN NOT NULL, expires_at DATETIME DEFAULT NULL, PRIMARY KEY(id)); +CREATE INDEX "oauth_auth_codes_user_id_index" on "oauth_auth_codes" ("user_id"); +CREATE TABLE oauth_clients (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id BIGINT UNSIGNED DEFAULT NULL, name VARCHAR(255) NOT NULL, secret VARCHAR(100) DEFAULT NULL, provider VARCHAR(255) DEFAULT NULL, redirect CLOB NOT NULL, personal_access_client BOOLEAN NOT NULL, password_client BOOLEAN NOT NULL, revoked BOOLEAN NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, authorized_webhook_url VARCHAR(255) DEFAULT NULL, privacy_policy_url VARCHAR(255) DEFAULT NULL, webhooks_enabled BOOLEAN DEFAULT 0 NOT NULL); +CREATE INDEX oauth_clients_user_id_index ON oauth_clients (user_id); +CREATE TABLE oauth_personal_access_clients (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, client_id BIGINT UNSIGNED NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL); +CREATE INDEX "train_stations_rilidentifier_index" on "train_stations" ("rilIdentifier"); +CREATE TABLE IF NOT EXISTS "webhook_creation_requests" ("id" varchar not null, "user_id" integer not null, "oauth_client_id" integer not null, "revoked" tinyint(1) not null default '0', "expires_at" datetime not null, "events" varchar not null, "url" text not null, foreign key("user_id") references "users"("id") on delete cascade on update cascade, foreign key("oauth_client_id") references "oauth_clients"("id") on delete cascade on update cascade, primary key ("id")); +CREATE TABLE failed_jobs (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, uuid VARCHAR(255) NOT NULL, connection CLOB NOT NULL, queue CLOB NOT NULL, payload CLOB NOT NULL, exception CLOB NOT NULL, failed_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL); +CREATE UNIQUE INDEX failed_jobs_uuid_unique ON failed_jobs (uuid); +CREATE TABLE hafas_trips (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, trip_id VARCHAR(255) NOT NULL COLLATE "BINARY", category VARCHAR(255) NOT NULL COLLATE "BINARY", number VARCHAR(255) NOT NULL COLLATE "BINARY", linename VARCHAR(255) NOT NULL COLLATE "BINARY", polyline_id INTEGER DEFAULT NULL, departure DATETIME DEFAULT NULL, arrival DATETIME DEFAULT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, operator_id INTEGER DEFAULT NULL, last_refreshed DATETIME DEFAULT NULL, journey_number INTEGER DEFAULT NULL, "source" varchar not null default 'hafas', "user_id" integer, "origin_id" integer, "destination_id" integer); +CREATE INDEX hafas_trips_created_at_trip_id_index ON hafas_trips (created_at, trip_id); +CREATE UNIQUE INDEX hafas_trips_trip_id_unique ON hafas_trips (trip_id); +CREATE TABLE events (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, station_id BIGINT UNSIGNED DEFAULT NULL, name VARCHAR(255) NOT NULL, slug VARCHAR(255) NOT NULL, hashtag VARCHAR(255) DEFAULT NULL, host VARCHAR(255) DEFAULT NULL, url VARCHAR(255) DEFAULT NULL, "begin" DATETIME NOT NULL, "end" DATETIME NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, event_start DATETIME DEFAULT NULL, event_end DATETIME DEFAULT NULL, approved_by INTEGER DEFAULT NULL, FOREIGN KEY (station_id) REFERENCES train_stations (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE); +CREATE UNIQUE INDEX events_slug_unique ON events (slug); +CREATE INDEX IDX_5387574A21BDB235 ON events (station_id); +CREATE TABLE event_suggestions (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id INTEGER DEFAULT NULL, station_id INTEGER DEFAULT NULL, name VARCHAR(255) NOT NULL COLLATE "BINARY", host VARCHAR(255) DEFAULT NULL COLLATE "BINARY", url VARCHAR(255) DEFAULT NULL COLLATE "BINARY", "begin" DATETIME DEFAULT NULL, "end" DATETIME DEFAULT NULL, processed BOOLEAN DEFAULT 0 NOT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, hashtag VARCHAR(255) DEFAULT NULL COLLATE "BINARY", FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE, FOREIGN KEY (station_id) REFERENCES train_stations (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE); +CREATE INDEX IDX_3A3F5594A76ED395 ON event_suggestions (user_id); +CREATE INDEX IDX_3A3F559439902DA8 ON event_suggestions (station_id); +CREATE TABLE IF NOT EXISTS "webhook_events" ("webhook_id" integer not null, "event" varchar not null, foreign key("webhook_id") references "webhooks"("id") on delete cascade on update cascade, primary key ("webhook_id", "event")); +CREATE TABLE webhooks (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, oauth_client_id INTEGER NOT NULL, user_id INTEGER NOT NULL, url CLOB NOT NULL COLLATE "BINARY", secret CLOB DEFAULT NULL COLLATE "BINARY", created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, FOREIGN KEY (oauth_client_id) REFERENCES oauth_clients (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, FOREIGN KEY (user_id) REFERENCES users (id) ON UPDATE CASCADE ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE); +CREATE INDEX IDX_998C4FDDDCA49ED ON webhooks (oauth_client_id); +CREATE INDEX IDX_998C4FDDA76ED395 ON webhooks (user_id); +CREATE TABLE social_login_profiles (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, user_id BIGINT UNSIGNED NOT NULL, twitter_id BIGINT UNSIGNED DEFAULT NULL, mastodon_id VARCHAR(255) DEFAULT NULL COLLATE "BINARY", mastodon_server BIGINT UNSIGNED DEFAULT NULL, mastodon_token CLOB DEFAULT NULL COLLATE "BINARY", created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, mastodon_visibility INTEGER DEFAULT 1 NOT NULL); +CREATE UNIQUE INDEX social_login_profiles_twitter_id_unique ON social_login_profiles (twitter_id); +CREATE TABLE IF NOT EXISTS "permissions" ("id" integer primary key autoincrement not null, "name" varchar not null, "guard_name" varchar not null, "created_at" datetime, "updated_at" datetime); +CREATE UNIQUE INDEX "permissions_name_guard_name_unique" on "permissions" ("name", "guard_name"); +CREATE TABLE IF NOT EXISTS "roles" ("id" integer primary key autoincrement not null, "name" varchar not null, "guard_name" varchar not null, "created_at" datetime, "updated_at" datetime); +CREATE UNIQUE INDEX "roles_name_guard_name_unique" on "roles" ("name", "guard_name"); +CREATE TABLE IF NOT EXISTS "model_has_permissions" ("permission_id" integer not null, "model_type" varchar not null, "model_id" integer not null, foreign key("permission_id") references "permissions"("id") on delete cascade, primary key ("permission_id", "model_id", "model_type")); +CREATE INDEX "model_has_permissions_model_id_model_type_index" on "model_has_permissions" ("model_id", "model_type"); +CREATE TABLE IF NOT EXISTS "model_has_roles" ("role_id" integer not null, "model_type" varchar not null, "model_id" integer not null, foreign key("role_id") references "roles"("id") on delete cascade, primary key ("role_id", "model_id", "model_type")); +CREATE INDEX "model_has_roles_model_id_model_type_index" on "model_has_roles" ("model_id", "model_type"); +CREATE TABLE IF NOT EXISTS "role_has_permissions" ("permission_id" integer not null, "role_id" integer not null, foreign key("permission_id") references "permissions"("id") on delete cascade, foreign key("role_id") references "roles"("id") on delete cascade, primary key ("permission_id", "role_id")); +CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(255) DEFAULT NULL COLLATE "BINARY", username VARCHAR(255) NOT NULL COLLATE "BINARY", avatar VARCHAR(255) DEFAULT NULL COLLATE "BINARY", email VARCHAR(255) DEFAULT NULL COLLATE "BINARY", email_verified_at DATETIME DEFAULT NULL, privacy_ack_at DATETIME DEFAULT NULL, password VARCHAR(255) DEFAULT NULL COLLATE "BINARY", home_id BIGINT UNSIGNED DEFAULT NULL, remember_token VARCHAR(255) DEFAULT NULL COLLATE "BINARY", created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, private_profile BOOLEAN DEFAULT 0 NOT NULL, prevent_index BOOLEAN DEFAULT 0 NOT NULL, language VARCHAR(255) DEFAULT NULL COLLATE "BINARY", last_login DATETIME DEFAULT NULL, default_status_visibility INTEGER DEFAULT 0 NOT NULL, privacy_hide_days INTEGER DEFAULT NULL, shadow_banned BOOLEAN DEFAULT 0 NOT NULL, likes_enabled BOOLEAN DEFAULT 1 NOT NULL, mapprovider VARCHAR(255) DEFAULT 'cargo' NOT NULL COLLATE "BINARY", timezone VARCHAR(255) DEFAULT 'Europe/Berlin' NOT NULL COLLATE "BINARY"); +CREATE UNIQUE INDEX users_username_unique ON users (username); +CREATE UNIQUE INDEX users_email_unique ON users (email); +CREATE INDEX users_shadow_banned_index ON users (shadow_banned); +CREATE TABLE statuses (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, body CLOB DEFAULT NULL COLLATE "BINARY", user_id BIGINT UNSIGNED NOT NULL, business SMALLINT UNSIGNED DEFAULT 0, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, event_id INTEGER DEFAULT NULL, visibility INTEGER DEFAULT 0 NOT NULL, tweet_id VARCHAR(255) DEFAULT NULL COLLATE "BINARY", mastodon_post_id VARCHAR(255) DEFAULT NULL COLLATE "BINARY", "client_id" integer); +CREATE INDEX statuses_user_id_mastodon_post_id_created_at_index ON statuses (user_id, mastodon_post_id, created_at); +CREATE TABLE train_checkins (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, status_id BIGINT UNSIGNED NOT NULL, trip_id VARCHAR(255) NOT NULL, origin BIGINT UNSIGNED NOT NULL, destination BIGINT UNSIGNED NOT NULL, distance INTEGER UNSIGNED DEFAULT NULL --meters +, departure DATETIME DEFAULT NULL, arrival DATETIME DEFAULT NULL, points INTEGER DEFAULT NULL, created_at DATETIME DEFAULT NULL, updated_at DATETIME DEFAULT NULL, user_id INTEGER DEFAULT NULL, forced BOOLEAN DEFAULT 0 NOT NULL, manual_departure DATETIME DEFAULT NULL, manual_arrival DATETIME DEFAULT NULL, duration INTEGER DEFAULT NULL, "origin_stopover_id" integer, "destination_stopover_id" integer); +CREATE INDEX train_checkins_departure_arrival_status_id_index ON train_checkins (departure, arrival, status_id); +CREATE INDEX train_checkins_user_id_arrival_index ON train_checkins (user_id, arrival); +CREATE UNIQUE INDEX user_trip_origin_departure ON train_checkins (user_id, trip_id, origin, departure); +CREATE UNIQUE INDEX train_checkins_status_id_unique ON train_checkins (status_id); +CREATE TABLE IF NOT EXISTS "activity_log" ("id" integer primary key autoincrement not null, "log_name" varchar, "description" text not null, "subject_type" varchar, "subject_id" integer, "causer_type" varchar, "causer_id" integer, "properties" text, "created_at" datetime, "updated_at" datetime, "event" varchar, "batch_uuid" varchar); +CREATE INDEX "subject" on "activity_log" ("subject_type", "subject_id"); +CREATE INDEX "causer" on "activity_log" ("causer_type", "causer_id"); +CREATE INDEX "activity_log_log_name_index" on "activity_log" ("log_name"); +CREATE TABLE IF NOT EXISTS "mentions" ("id" integer primary key autoincrement not null, "status_id" integer not null, "mentioned_id" integer not null, "position" integer not null, "length" integer not null, "created_at" datetime, "updated_at" datetime, foreign key("status_id") references "statuses"("id") on delete cascade, foreign key("mentioned_id") references "users"("id") on delete cascade); +CREATE UNIQUE INDEX "mentions_status_id_mentioned_id_position_unique" on "mentions" ("status_id", "mentioned_id", "position"); +CREATE TABLE IF NOT EXISTS "wikidata_entities" ("id" varchar not null, "data" text, "last_updated_at" datetime, "created_at" datetime, "updated_at" datetime, primary key ("id")); +CREATE INDEX "ifopt" on "train_stations" ("ifopt_a", "ifopt_b", "ifopt_c", "ifopt_d", "ifopt_e"); +INSERT INTO migrations VALUES(1,'2014_10_12_000000_create_users_table',1); +INSERT INTO migrations VALUES(2,'2014_10_12_100000_create_password_resets_table',1); +INSERT INTO migrations VALUES(3,'2016_06_01_000001_create_oauth_auth_codes_table',1); +INSERT INTO migrations VALUES(4,'2016_06_01_000002_create_oauth_access_tokens_table',1); +INSERT INTO migrations VALUES(5,'2016_06_01_000003_create_oauth_refresh_tokens_table',1); +INSERT INTO migrations VALUES(6,'2016_06_01_000004_create_oauth_clients_table',1); +INSERT INTO migrations VALUES(7,'2016_06_01_000005_create_oauth_personal_access_clients_table',1); +INSERT INTO migrations VALUES(8,'2018_02_05_000000_create_queue_monitor_table',1); +INSERT INTO migrations VALUES(9,'2019_08_06_184725_create_social_login_profiles_table',1); +INSERT INTO migrations VALUES(10,'2019_08_09_003647_create_statuses_table',1); +INSERT INTO migrations VALUES(11,'2019_08_09_003814_create_likes_table',1); +INSERT INTO migrations VALUES(12,'2019_08_09_003837_create_follows_table',1); +INSERT INTO migrations VALUES(13,'2019_08_11_233556_create_mastodon_servers_table',1); +INSERT INTO migrations VALUES(14,'2019_08_13_155546_create_hafas_trips_table',1); +INSERT INTO migrations VALUES(15,'2019_08_13_162744_create_train_stations_table',1); +INSERT INTO migrations VALUES(16,'2019_08_14_013806_create_train_checkins_table',1); +INSERT INTO migrations VALUES(17,'2019_08_19_173342_create_sessions_table',1); +INSERT INTO migrations VALUES(18,'2019_11_04_200120_create_privacy_agreements_table',1); +INSERT INTO migrations VALUES(19,'2019_11_22_220440_create_poly_lines_table',1); +INSERT INTO migrations VALUES(20,'2019_12_14_130742_create_events_table',1); +INSERT INTO migrations VALUES(21,'2019_12_18_222050_connect_statuses_and_events',1); +INSERT INTO migrations VALUES(22,'2019_12_20_221724_create_user_roles',1); +INSERT INTO migrations VALUES(23,'2020_02_20_162218_create_notifications_table',1); +INSERT INTO migrations VALUES(24,'2020_08_05_151702_change_train_station_table',1); +INSERT INTO migrations VALUES(25,'2020_09_27_190346_migrate_laravel_passport_to_v9',1); +INSERT INTO migrations VALUES(26,'2020_09_28_150313_migrate_notifications_to_laravel8',1); +INSERT INTO migrations VALUES(27,'2020_09_28_170000_add_foreign_keys_to_social_login_profiles',1); +INSERT INTO migrations VALUES(28,'2020_09_28_170001_unify_columns_from_train_stations',1); +INSERT INTO migrations VALUES(29,'2020_09_28_170002_add_foreign_keys_to_events',1); +INSERT INTO migrations VALUES(30,'2020_09_28_170003_add_foreign_keys_to_follows',1); +INSERT INTO migrations VALUES(31,'2020_09_28_170004_add_keys_to_poly_lines',1); +INSERT INTO migrations VALUES(32,'2020_09_28_170005_add_foreign_keys_to_hafas_trips',1); +INSERT INTO migrations VALUES(33,'2020_09_28_170006_add_foreign_keys_to_likes',1); +INSERT INTO migrations VALUES(34,'2020_09_28_170007_add_foreign_keys_to_sessions',1); +INSERT INTO migrations VALUES(35,'2020_09_28_170008_add_foreign_keys_to_statuses',1); +INSERT INTO migrations VALUES(36,'2020_09_28_170009_add_foreign_keys_to_train_checkins',1); +INSERT INTO migrations VALUES(37,'2020_09_28_170010_add_foreign_keys_to_users',1); +INSERT INTO migrations VALUES(38,'2020_10_05_184500_add_unique_key_to_events',1); +INSERT INTO migrations VALUES(39,'2020_10_16_175602_add_unique_key_to_likes',1); +INSERT INTO migrations VALUES(40,'2020_11_18_101929_add_user_private_profile_key',1); +INSERT INTO migrations VALUES(41,'2021_01_26_203951_create_train_stopovers_table',1); +INSERT INTO migrations VALUES(42,'2021_02_01_000000_add_unique_key_to_poly_lines',1); +INSERT INTO migrations VALUES(43,'2021_02_15_000000_create_ics_tokens_table',1); +INSERT INTO migrations VALUES(44,'2021_02_20_155443_remove_static_points_from_users',1); +INSERT INTO migrations VALUES(45,'2021_02_20_213248_add_ril_identifier_to_train_stations',1); +INSERT INTO migrations VALUES(46,'2021_02_23_170640_create_hafas_operators_table',1); +INSERT INTO migrations VALUES(47,'2021_02_23_171038_add_hafas_operator_to_hafas_trips',1); +INSERT INTO migrations VALUES(48,'2021_02_23_185026_change_avatar_to_be_null_on_users',1); +INSERT INTO migrations VALUES(49,'2021_04_21_102707_change_statuses_to_accept_business_checkin_as_integer',1); +INSERT INTO migrations VALUES(50,'2021_04_28_230708_add_last_accessed_and_name_to_ics_tokens',1); +INSERT INTO migrations VALUES(51,'2021_04_29_150026_create_follow_requests_table',1); +INSERT INTO migrations VALUES(52,'2021_05_01_165202_add_privacy_search_engine_to_users',1); +INSERT INTO migrations VALUES(53,'2021_05_10_201216_add_language_to_users',1); +INSERT INTO migrations VALUES(54,'2021_05_12_211411_create_user_mutes_table',1); +INSERT INTO migrations VALUES(55,'2021_05_26_134022_remove_train_distance_and_duration_from_users',1); +INSERT INTO migrations VALUES(56,'2021_05_26_172817_create_event_suggestions_table',1); +INSERT INTO migrations VALUES(57,'2021_06_07_145349_add_visibility_to_statuses',1); +INSERT INTO migrations VALUES(58,'2021_06_08_200223_add_index_to_sessions_table',1); +INSERT INTO migrations VALUES(59,'2021_07_03_222039_add_last_login_to_users',1); +INSERT INTO migrations VALUES(60,'2021_07_04_002719_drop_points_calculation_table',1); +INSERT INTO migrations VALUES(61,'2021_07_24_124933_create_default_visibility_on_users',1); +INSERT INTO migrations VALUES(62,'2021_08_05_211128_change_column_for_train_checkins',1); +INSERT INTO migrations VALUES(63,'2021_08_05_214231_remove_delay_from_train_checkins',1); +INSERT INTO migrations VALUES(64,'2021_08_05_220132_add_user_id_to_train_checkins',1); +INSERT INTO migrations VALUES(65,'2021_10_08_132506_make_twitter_id_unique_in_social_login_profiles',1); +INSERT INTO migrations VALUES(66,'2021_10_08_160350_add_foreign_key_to_social_login_profiles',1); +INSERT INTO migrations VALUES(67,'2021_10_12_143849_drop-blogposts-table',1); +INSERT INTO migrations VALUES(68,'2021_11_03_211948_add_unique_key_to_train_checkins',1); +INSERT INTO migrations VALUES(69,'2021_11_06_193343_make_url_nullable_at_events',1); +INSERT INTO migrations VALUES(70,'2021_12_14_143156_add_user_arrival_index_to_train_checkins',1); +INSERT INTO migrations VALUES(71,'2022_01_06_224610_add_index_to_train_stopovers',1); +INSERT INTO migrations VALUES(72,'2022_01_06_230418_add_index_to_hafas_trips',1); +INSERT INTO migrations VALUES(73,'2022_03_03_104050_add_cancelled_attribute_to_stopover',1); +INSERT INTO migrations VALUES(74,'2022_03_07_000000_add_hide_status_days_to_users',1); +INSERT INTO migrations VALUES(75,'2022_03_11_000000_migrate_train_checkin_category',1); +INSERT INTO migrations VALUES(76,'2022_03_18_000000_migrate_encryptables',1); +INSERT INTO migrations VALUES(77,'2022_03_28_000000_add_support_code_to_users',1); +INSERT INTO migrations VALUES(78,'2022_03_29_000000_add_index_to_train_stopovers',1); +INSERT INTO migrations VALUES(79,'2022_04_01_000000_remove_support_code_from_users',1); +INSERT INTO migrations VALUES(80,'2022_04_02_000000_change_unique_key_to_support_multiple_stopovers_per_station',1); +INSERT INTO migrations VALUES(81,'2022_04_02_000000_create_remarks_table',1); +INSERT INTO migrations VALUES(82,'2022_04_02_000001_create_trip_remarks_table',1); +INSERT INTO migrations VALUES(83,'2022_04_03_000000_create_user_agents_table',1); +INSERT INTO migrations VALUES(84,'2022_04_03_000001_create_api_logs_table',1); +INSERT INTO migrations VALUES(85,'2022_04_07_085923_change_status_code_datatype_in_api_logs_table',1); +INSERT INTO migrations VALUES(86,'2022_05_22_000000_add_station_id_to_events',1); +INSERT INTO migrations VALUES(87,'2022_05_29_000000_create_carriage_sequences_table',1); +INSERT INTO migrations VALUES(88,'2022_06_04_000000_create_jobs_table',1); +INSERT INTO migrations VALUES(89,'2022_06_04_000001_make_order_number_nullable_at_carriage_sequences',1); +INSERT INTO migrations VALUES(90,'2022_07_21_000000_add_index_to_api_logs',1); +INSERT INTO migrations VALUES(91,'2022_07_21_000001_add_index_to_user_agents',1); +INSERT INTO migrations VALUES(92,'2022_07_23_000000_add_forced_to_train_checkins',1); +INSERT INTO migrations VALUES(93,'2022_08_31_000000_add_last_refreshed_to_hafas_trips',1); +INSERT INTO migrations VALUES(94,'2022_08_31_000001_add_index2_to_train_stopovers',1); +INSERT INTO migrations VALUES(95,'2022_09_08_000000_create_locations_table',1); +INSERT INTO migrations VALUES(96,'2022_09_25_000000_create_cache_table',1); +INSERT INTO migrations VALUES(97,'2022_09_26_000000_fill_planned_departure_and_arrival_at_train_stopovers',1); +INSERT INTO migrations VALUES(98,'2022_09_26_000001_add_tweet_id_to_statuses',1); +INSERT INTO migrations VALUES(99,'2022_10_11_000000_create_failed_jobs_table',1); +INSERT INTO migrations VALUES(100,'2022_10_17_000000_default_uuid_field',1); +INSERT INTO migrations VALUES(101,'2022_10_22_000000_add_unique_key_to_train_stopovers',1); +INSERT INTO migrations VALUES(102,'2022_11_25_223003_add_toot_id_to_status_table',1); +INSERT INTO migrations VALUES(103,'2022_12_11_000000_drop_trip_remarks',1); +INSERT INTO migrations VALUES(104,'2022_12_11_000001_drop_remarks',1); +INSERT INTO migrations VALUES(105,'2022_12_23_000000_create_status_tags_table',1); +INSERT INTO migrations VALUES(106,'2022_12_25_000000_create_user_blocks_table',1); +INSERT INTO migrations VALUES(107,'2022_19_10_000000_add_twitter_refresh_token',1); +INSERT INTO migrations VALUES(108,'2023_01_08_202020_remove_always_dbl_flag_from_users_table',1); +INSERT INTO migrations VALUES(109,'2023_01_21_000000_add_journey_number_to_hafas_trips',1); +INSERT INTO migrations VALUES(110,'2023_01_28_000000_migrate_passport_from_v7_to_v8',1); +INSERT INTO migrations VALUES(111,'2023_01_30_173822_add_scopes_to_existing_oauth_access_tokens',1); +INSERT INTO migrations VALUES(112,'2023_02_04_184426_extend_oauth_clients_with_custom_data',1); +INSERT INTO migrations VALUES(113,'2023_02_07_202300_add_mastodon_visibility_field_to_social_login_profiles_table',1); +INSERT INTO migrations VALUES(114,'2023_02_11_000000_remove_api_usage',1); +INSERT INTO migrations VALUES(115,'2023_02_11_000001_remove_locations_table',1); +INSERT INTO migrations VALUES(116,'2023_03_01_000000_update_queue_monitor_table',1); +INSERT INTO migrations VALUES(117,'2023_03_06_000000_add_override_arrival_and_departure_to_train_checkins',1); +INSERT INTO migrations VALUES(118,'2023_03_23_000000_add_index_to_train_checkins',1); +INSERT INTO migrations VALUES(119,'2023_03_23_000000_migrate_oauth_access_tokens',1); +INSERT INTO migrations VALUES(120,'2023_03_23_000000_migrate_oauth_auth_codes',1); +INSERT INTO migrations VALUES(121,'2023_03_23_000000_migrate_oauth_clients',1); +INSERT INTO migrations VALUES(122,'2023_03_23_000000_migrate_oauth_personal_access_clients',1); +INSERT INTO migrations VALUES(123,'2023_03_23_000001_add_index_to_users',1); +INSERT INTO migrations VALUES(124,'2023_03_23_000002_add_index_to_train_stations',1); +INSERT INTO migrations VALUES(125,'2023_03_23_000003_create_webhooks_table',1); +INSERT INTO migrations VALUES(126,'2023_03_23_000004_create_webhook_creation_requests_table',1); +INSERT INTO migrations VALUES(127,'2023_03_23_215105_change_index_at_train_checkins',1); +INSERT INTO migrations VALUES(128,'2023_03_29_000000_add_shadow_banned_to_users',1); +INSERT INTO migrations VALUES(129,'2023_04_25_000000_add_source_to_poly_lines',1); +INSERT INTO migrations VALUES(130,'2023_05_03_144452_add_job_uuid_and_retried_to_queue_monitor_table',1); +INSERT INTO migrations VALUES(131,'2023_05_05_000000_drop_carriage_sequences',1); +INSERT INTO migrations VALUES(132,'2023_05_07_135454_add_likes_enabled_field_to_users_table',1); +INSERT INTO migrations VALUES(133,'2023_05_09_000000_make_station_id_null_on_events',1); +INSERT INTO migrations VALUES(134,'2023_05_10_000000_default_uuid_field',1); +INSERT INTO migrations VALUES(135,'2023_06_06_000000_delete_all_notifications',1); +INSERT INTO migrations VALUES(136,'2023_06_09_161642_add_mapprovider_field_to_users_table',1); +INSERT INTO migrations VALUES(137,'2023_06_13_213444_expand_event_date_restrictions',1); +INSERT INTO migrations VALUES(138,'2023_07_06_201721_rename_legacy_stopovers',1); +INSERT INTO migrations VALUES(139,'2023_07_07_183520_add_timezone_to_users',1); +INSERT INTO migrations VALUES(140,'2023_07_08_090008_add_time_information_to_stations',1); +INSERT INTO migrations VALUES(141,'2023_07_09_000000_make_hashtag_nullable_on_events',1); +INSERT INTO migrations VALUES(142,'2023_07_13_144452_add_queued_at_column_to_queue_monitor_table',1); +INSERT INTO migrations VALUES(143,'2023_07_24_000000_add_user_mastodon_index_to_statuses',1); +INSERT INTO migrations VALUES(144,'2023_07_26_000000_add_duration_to_train_checkins',1); +INSERT INTO migrations VALUES(145,'2023_08_06_000000_rename_manual_arrival_and_departure_at_train_checkins',1); +INSERT INTO migrations VALUES(146,'2023_08_06_000001_add_hashtag_to_event_suggestions',1); +INSERT INTO migrations VALUES(147,'2023_08_06_000002_rename_station_id_at_event_suggestions',1); +INSERT INTO migrations VALUES(148,'2023_08_19_160842_add_webhook_events_table',1); +INSERT INTO migrations VALUES(149,'2023_08_19_161454_migrate_webhook_events_from_bitmasks_to_table',1); +INSERT INTO migrations VALUES(150,'2023_08_19_174051_drop_webhook_events_column',1); +INSERT INTO migrations VALUES(151,'2023_09_22_194607_add_experimental_setting_to_users',1); +INSERT INTO migrations VALUES(152,'2023_09_23_162754_add-parent-to-polylines',1); +INSERT INTO migrations VALUES(153,'2023_11_20_000000_drop_user_agents',1); +INSERT INTO migrations VALUES(154,'2023_11_20_000001_drop_locations',1); +INSERT INTO migrations VALUES(155,'2023_11_20_000002_drop_remarks',1); +INSERT INTO migrations VALUES(156,'2023_11_21_000000_drop_twitter_secrets',1); +INSERT INTO migrations VALUES(157,'2023_11_21_000001_create_permission_tables',1); +INSERT INTO migrations VALUES(158,'2023_11_21_000002_add_default_permissions',1); +INSERT INTO migrations VALUES(159,'2023_11_21_000003_drop_role_from_users',1); +INSERT INTO migrations VALUES(160,'2023_11_21_000004_drop_experimental_from_users',1); +INSERT INTO migrations VALUES(161,'2023_11_22_000000_add_source_to_trips',1); +INSERT INTO migrations VALUES(162,'2023_11_23_000000_remove_type_from_statuses',1); +INSERT INTO migrations VALUES(163,'2023_11_23_000001_fix_departure_column_on_train_checkins',1); +INSERT INTO migrations VALUES(164,'2023_11_23_000002_add_user_id_to_hafas_trips',1); +INSERT INTO migrations VALUES(165,'2023_11_27_000000_drop_delay_column_in_hafas_trips',1); +INSERT INTO migrations VALUES(166,'2023_12_17_000000_create_activity_log_table',1); +INSERT INTO migrations VALUES(167,'2023_12_17_000001_add_event_column_to_activity_log_table',1); +INSERT INTO migrations VALUES(168,'2023_12_17_000002_add_batch_uuid_column_to_activity_log_table',1); +INSERT INTO migrations VALUES(169,'2023_12_17_000003_add_event_history_permission',1); +INSERT INTO migrations VALUES(170,'2023_12_18_000000_add_origin_and_destination_stopover_foreign_to_train_checkins',1); +INSERT INTO migrations VALUES(171,'2023_12_20_000000_migrate_stopover_relation_id_in_train_checkins',1); +INSERT INTO migrations VALUES(172,'2023_12_29_000000_add_client_id_to_statuses',1); +INSERT INTO migrations VALUES(173,'2024_01_28_201122_cache_current_number_of_statuses_and_users',1); +INSERT INTO migrations VALUES(174,'2024_01_29_000000_add_station_permissions',1); +INSERT INTO migrations VALUES(175,'2024_01_30_000000_add_activity_permissions',1); +INSERT INTO migrations VALUES(176,'2024_02_01_000000_add_permissions_for_manual_trips_beta',1); +INSERT INTO migrations VALUES(177,'2024_02_08_000000_create_mentions_table',1); +INSERT INTO migrations VALUES(178,'2024_03_01_000000_create_wikidata_entities_table',1); +INSERT INTO migrations VALUES(179,'2024_03_01_000001_add_wikidata_id_to_stations',1); +INSERT INTO migrations VALUES(180,'2024_03_10_211526_add_ifopt_to_stations',1); +INSERT INTO migrations VALUES(181,'2024_03_11_000000_add_origin_and_destination_id_to_trips',1); diff --git a/database/seeders/Constants/PermissionSeeder.php b/database/seeders/Constants/PermissionSeeder.php new file mode 100644 index 000000000..ab2076f9e --- /dev/null +++ b/database/seeders/Constants/PermissionSeeder.php @@ -0,0 +1,62 @@ + 'admin']); + $roleEventModerator = Role::updateOrCreate(['name' => 'event-moderator']); + $roleOpenBeta = Role::updateOrCreate(['name' => 'open-beta']); + $roleClosedBeta = Role::updateOrCreate(['name' => 'closed-beta']); + + //Create permissions + $permissionViewBackend = Permission::updateOrCreate(['name' => 'view-backend']); + $permissionViewEvents = Permission::updateOrCreate(['name' => 'view-events']); + $permissionAcceptEvents = Permission::updateOrCreate(['name' => 'accept-events']); + $permissionDenyEvents = Permission::updateOrCreate(['name' => 'deny-events']); + $permissionCreateEvents = Permission::updateOrCreate(['name' => 'create-events']); + $permissionUpdateEvents = Permission::updateOrCreate(['name' => 'update-events']); + $permissionDeleteEvents = Permission::updateOrCreate(['name' => 'delete-events']); + $permissionCreateManualTrip = Permission::updateOrCreate(['name' => 'create-manual-trip']); + $permissionViewActivity = Permission::updateOrCreate(['name' => 'view activity']); + $permissionViewEventHistory = Permission::updateOrCreate(['name' => 'view event history']); + $permissionCreateStations = Permission::updateOrCreate(['name' => 'create stations']); + $permissionUpdateStations = Permission::updateOrCreate(['name' => 'update stations']); + $permissionDeleteStations = Permission::updateOrCreate(['name' => 'delete stations']); + + //Assign permissions to admin role + $roleAdmin->givePermissionTo($permissionViewBackend); + $roleAdmin->givePermissionTo($permissionViewEvents); + $roleAdmin->givePermissionTo($permissionAcceptEvents); + $roleAdmin->givePermissionTo($permissionDenyEvents); + $roleAdmin->givePermissionTo($permissionCreateEvents); + $roleAdmin->givePermissionTo($permissionUpdateEvents); + $roleAdmin->givePermissionTo($permissionDeleteEvents); + $roleAdmin->givePermissionTo($permissionCreateManualTrip); + $roleAdmin->givePermissionTo($permissionViewActivity); + $roleAdmin->givePermissionTo($permissionViewEventHistory); + $roleAdmin->givePermissionTo($permissionCreateStations); + $roleAdmin->givePermissionTo($permissionUpdateStations); + $roleAdmin->givePermissionTo($permissionDeleteStations); + + //Assign permissions to event-moderator role + $roleEventModerator->givePermissionTo($permissionViewBackend); + $roleEventModerator->givePermissionTo($permissionViewEvents); + $roleEventModerator->givePermissionTo($permissionAcceptEvents); + $roleEventModerator->givePermissionTo($permissionDenyEvents); + $roleEventModerator->givePermissionTo($permissionUpdateEvents); + + //Assign permissions to open-beta role + $roleClosedBeta->givePermissionTo($permissionCreateManualTrip); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 6a92ebfff..76c2544e1 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -3,14 +3,19 @@ namespace Database\Seeders; use App\Models\EventSuggestion; -use App\Models\Trip; use App\Models\Station; +use App\Models\Trip; +use Database\Seeders\Constants\PermissionSeeder; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { public function run(): void { + //Seed obligatory constants + $this->call(PermissionSeeder::class); + + //Seed example data for development $this->call(UsersTableSeeder::class); $this->call(ClientSeeder::class); $this->call(FollowTableSeeder::class); diff --git a/tests/Feature/Transport/ManualTripCreatorTest.php b/tests/Feature/Transport/ManualTripCreatorTest.php index 3206063a0..4156e901f 100644 --- a/tests/Feature/Transport/ManualTripCreatorTest.php +++ b/tests/Feature/Transport/ManualTripCreatorTest.php @@ -44,8 +44,8 @@ public function testCanCreateManualTripsAndCheckin(): void { 'linename' => $trip->linename, 'journey_number' => $trip->journey_number, 'operator_id' => $trip->operator_id, - 'origin' => $trip->origin, - 'destination' => $trip->destination, + 'origin_id' => $trip->origin_id, + 'destination_id' => $trip->destination_id, 'departure' => $trip->departure, 'arrival' => $trip->arrival, 'source' => $trip->source, diff --git a/tests/TestCase.php b/tests/TestCase.php index d7c1025b9..40300cfcc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -136,6 +136,7 @@ abstract class TestCase extends BaseTestCase protected function setUp(): void { parent::setUp(); + $this->artisan('db:seed --class=Database\\\\Seeders\\\\Constants\\\\PermissionSeeder'); $this->artisan('db:seed --class=Database\\\\Seeders\\\\PrivacyAgreementSeeder'); } diff --git a/update.sh b/update.sh index 9a0e72359..530f38ff4 100755 --- a/update.sh +++ b/update.sh @@ -19,6 +19,7 @@ run_migrations() { post_run() { php artisan optimize php artisan queue:restart + php artisan db:seed --class=Database\\Seeders\\Constants\\PermissionSeeder php artisan up }