Skip to content
Open
Show file tree
Hide file tree
Changes from 15 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
12 changes: 8 additions & 4 deletions Sources/Db/APIs/PostgreSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -975,14 +975,18 @@ public function backup_table(string $table, string $backup_table): object|bool
);
}

/**
* @todo Should we create backups of sequences as well?
*/
// The copy takes the columns and their types. It does not take their
// defaults, because a default is copied as the expression it is written
// with: a column fed by a sequence would arrive pointing at the live
// table's sequence, leaving the backup as an object that sequence
// cannot be dropped without and drawing ids from it if anything were
// inserted here. What each column defaults to is kept by the upgrader
// alongside the rest of the table's definition, which is a fuller
// record than a copy of the defaults would have been.
$result = $this->query(
'CREATE TABLE {raw:backup_table}
(
LIKE {raw:table}
INCLUDING DEFAULTS
)',
[
'backup_table' => $backup_table,
Expand Down
110 changes: 110 additions & 0 deletions Sources/Db/Schema/v3_0/MigrationData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2026 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 4
*/

declare(strict_types=1);

namespace SMF\Db\Schema\v3_0;

use SMF\Db\Schema\Column;
use SMF\Db\Schema\DbIndex;
use SMF\Db\Schema\Table;

/**
* Defines all the properties for a database table.
*/
class MigrationData extends Table
{
/****************
* Public methods
****************/

/**
* Constructor.
*/
public function __construct()
{
$this->name = 'migration_data';

$this->columns = [
'id_entry' => new Column(
name: 'id_entry',
type: 'int',
unsigned: true,
not_null: true,
auto: true,
),
'id_run' => new Column(
name: 'id_run',
type: 'varchar',
size: 36,
not_null: true,
default: '',
),
'migration' => new Column(
name: 'migration',
type: 'varchar',
size: 255,
not_null: true,
default: '',
),
'data_type' => new Column(
name: 'data_type',
type: 'varchar',
size: 30,
not_null: true,
default: '',
),
'data_key' => new Column(
name: 'data_key',
type: 'varchar',
size: 255,
not_null: true,
default: '',
),
'data' => new Column(
name: 'data',
type: 'mediumtext',
not_null: true,
),
'time_added' => new Column(
name: 'time_added',
type: 'bigint',
unsigned: true,
not_null: true,
default: 0,
),
];

$this->indexes = [
'primary' => new DbIndex(
type: 'primary',
columns: [
[
'name' => 'id_entry',
],
],
),
'idx_run' => new DbIndex(
name: 'idx_run',
columns: [
[
'name' => 'id_run',
],
[
'name' => 'data_type',
],
],
),
];
}
}
137 changes: 137 additions & 0 deletions Sources/Db/Schema/v3_0/MigrationRuns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

/**
* Simple Machines Forum (SMF)
*
* @package SMF
* @author Simple Machines https://www.simplemachines.org
* @copyright 2026 Simple Machines and individual contributors
* @license https://www.simplemachines.org/about/smf/license.php BSD
*
* @version 3.0 Alpha 4
*/

declare(strict_types=1);

namespace SMF\Db\Schema\v3_0;

use SMF\Db\Schema\Column;
use SMF\Db\Schema\DbIndex;
use SMF\Db\Schema\Table;

/**
* Defines all the properties for a database table.
*/
class MigrationRuns extends Table
{
/****************
* Public methods
****************/

/**
* Constructor.
*/
public function __construct()
{
$this->name = 'migration_runs';

$this->columns = [
'id_run' => new Column(
name: 'id_run',
type: 'varchar',
size: 36,
not_null: true,
default: '',
),
'version_from' => new Column(
name: 'version_from',
type: 'varchar',
size: 20,
not_null: true,
default: '',
),
'version_to' => new Column(
name: 'version_to',
type: 'varchar',
size: 20,
not_null: true,
default: '',
),
'step' => new Column(
name: 'step',
type: 'smallint',
unsigned: true,
not_null: true,
default: 0,
),
'substep' => new Column(
name: 'substep',
type: 'int',
unsigned: true,
not_null: true,
default: 0,
),
'substep_start' => new Column(
name: 'substep_start',
type: 'int',
unsigned: true,
not_null: true,
default: 0,
),
'id_member' => new Column(
name: 'id_member',
type: 'int',
unsigned: true,
not_null: true,
default: 0,
),
'time_started' => new Column(
name: 'time_started',
type: 'bigint',
unsigned: true,
not_null: true,
default: 0,
),
'time_updated' => new Column(
name: 'time_updated',
type: 'bigint',
unsigned: true,
not_null: true,
default: 0,
),
'time_finished' => new Column(
name: 'time_finished',
type: 'bigint',
unsigned: true,
not_null: true,
default: 0,
),
'time_rolled_back' => new Column(
name: 'time_rolled_back',
type: 'bigint',
unsigned: true,
not_null: true,
default: 0,
),
];

$this->indexes = [
'primary' => new DbIndex(
type: 'primary',
columns: [
[
'name' => 'id_run',
],
],
),
'idx_time_finished' => new DbIndex(
name: 'idx_time_finished',
columns: [
[
'name' => 'time_finished',
],
],
),
];
}
}
Loading