Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 46 additions & 0 deletions migrations/2023_07_14_000002_delete_extra_polls_columns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of fof/polls.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;

// These columns were superseded by the `settings` JSON column. Sites upgrading
// from 1.x may already have had them dropped, so both directions are guarded
// rather than using Migration::dropColumns(), whose up/down are unguarded.
$columns = [
'public_poll' => fn (Blueprint $table) => $table->boolean('public_poll')->default(false),
'allow_multiple_votes' => fn (Blueprint $table) => $table->boolean('allow_multiple_votes')->default(false),
'max_votes' => fn (Blueprint $table) => $table->integer('max_votes')->unsigned()->default(0),
];

return [
'up' => function (Builder $schema) use ($columns) {
$existing = array_filter(
array_keys($columns),
fn (string $column) => $schema->hasColumn('polls', $column)
);

if ($existing !== []) {
$schema->table('polls', function (Blueprint $table) use ($existing) {
$table->dropColumn(array_values($existing));
});
}
},
'down' => function (Builder $schema) use ($columns) {
foreach ($columns as $name => $definition) {
if (!$schema->hasColumn('polls', $name)) {
$schema->table('polls', function (Blueprint $table) use ($definition) {
$definition($table);
});
}
}
},
];
18 changes: 0 additions & 18 deletions migrations/2026_04_15_000000_delete_extra_polls_columns.php

This file was deleted.

67 changes: 67 additions & 0 deletions migrations/2026_04_17_000000_alter_polls_add_draft_columns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

/*
* This file is part of fof/polls.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;

return [
'up' => function (Builder $schema) {
// This migration was released on 1.x under this same filename, so sites
// upgrading from 1.x may already have these columns. Each step is
// guarded to keep the migration safe to re-run against any state.
$columns = [
'published_at' => fn (Blueprint $table, string $after) => $table->timestamp('published_at')->nullable()->after($after),
'scheduled_publish_at' => fn (Blueprint $table, string $after) => $table->timestamp('scheduled_publish_at')->nullable()->after($after),
'scheduled_publish_error' => fn (Blueprint $table, string $after) => $table->text('scheduled_publish_error')->nullable()->after($after),
];

$after = 'end_date';

foreach ($columns as $name => $definition) {
if (!$schema->hasColumn('polls', $name)) {
$schema->table('polls', function (Blueprint $table) use ($definition, $after) {
$definition($table, $after);
});
}

$after = $name;
}

if (!$schema->hasIndex('polls', 'polls_scheduled_publish_at_index')) {
$schema->table('polls', function (Blueprint $table) {
$table->index('scheduled_publish_at', 'polls_scheduled_publish_at_index');
});
}

// Backfill: existing rows are considered published.
$schema->getConnection()->table('polls')
->whereNull('published_at')
->update(['published_at' => $schema->getConnection()->raw('created_at')]);
},
'down' => function (Builder $schema) {
if ($schema->hasIndex('polls', 'polls_scheduled_publish_at_index')) {
$schema->table('polls', function (Blueprint $table) {
$table->dropIndex('polls_scheduled_publish_at_index');
});
}

$existing = array_filter(
['published_at', 'scheduled_publish_at', 'scheduled_publish_error'],
fn (string $column) => $schema->hasColumn('polls', $column)
);

if ($existing !== []) {
$schema->table('polls', function (Blueprint $table) use ($existing) {
$table->dropColumn(array_values($existing));
});
}
},
];
35 changes: 0 additions & 35 deletions migrations/2026_05_18_000000_alter_polls_add_draft_columns.php

This file was deleted.

Loading