diff --git a/migrations/2023_07_14_000002_delete_extra_polls_columns.php b/migrations/2023_07_14_000002_delete_extra_polls_columns.php new file mode 100644 index 00000000..20d96511 --- /dev/null +++ b/migrations/2023_07_14_000002_delete_extra_polls_columns.php @@ -0,0 +1,46 @@ + 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); + }); + } + } + }, +]; diff --git a/migrations/2026_04_15_000000_delete_extra_polls_columns.php b/migrations/2026_04_15_000000_delete_extra_polls_columns.php deleted file mode 100644 index 7a4d0959..00000000 --- a/migrations/2026_04_15_000000_delete_extra_polls_columns.php +++ /dev/null @@ -1,18 +0,0 @@ - ['boolean', 'default' => false], - 'allow_multiple_votes' => ['boolean', 'default' => false], - 'max_votes' => ['integer', 'unsigned' => true, 'default' => 0], -]); diff --git a/migrations/2026_04_17_000000_alter_polls_add_draft_columns.php b/migrations/2026_04_17_000000_alter_polls_add_draft_columns.php new file mode 100644 index 00000000..36cf958b --- /dev/null +++ b/migrations/2026_04_17_000000_alter_polls_add_draft_columns.php @@ -0,0 +1,67 @@ + 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)); + }); + } + }, +]; diff --git a/migrations/2026_05_18_000000_alter_polls_add_draft_columns.php b/migrations/2026_05_18_000000_alter_polls_add_draft_columns.php deleted file mode 100644 index ca49d649..00000000 --- a/migrations/2026_05_18_000000_alter_polls_add_draft_columns.php +++ /dev/null @@ -1,35 +0,0 @@ - function (Builder $schema) { - $schema->table('polls', function (Blueprint $table) { - $table->timestamp('published_at')->nullable()->after('end_date'); - $table->timestamp('scheduled_publish_at')->nullable()->after('published_at'); - $table->text('scheduled_publish_error')->nullable()->after('scheduled_publish_at'); - $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) { - $schema->table('polls', function (Blueprint $table) { - $table->dropIndex('polls_scheduled_publish_at_index'); - $table->dropColumn(['published_at', 'scheduled_publish_at', 'scheduled_publish_error']); - }); - }, -];