1
0
mirror of https://github.com/flarum/core.git synced 2025-06-05 22:25:29 +02:00

feat: add automatic created/updated timestamps for various tables (#3435)

Adds timestamps for various tables:

- groups
- group_user
- group_permission
- tags
- discussion_tag
- post_mentions_post
- post_mentions_user
This commit is contained in:
Rafael Horvat 2022-06-07 21:35:27 +02:00 committed by GitHub
parent f882ff9bb5
commit 776f9bf132
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 236 additions and 1 deletions

View File

@ -0,0 +1,30 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed 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) {
$schema->table('post_mentions_post', function (Blueprint $table) {
$table->timestamp('created_at')->nullable();
});
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE `${prefix}post_mentions_post` MODIFY created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP");
},
'down' => function (Builder $schema) {
$schema->table('post_mentions_post', function (Blueprint $table) {
$table->dropColumn('created_at');
});
}
];

View File

@ -0,0 +1,30 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed 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) {
$schema->table('post_mentions_user', function (Blueprint $table) {
$table->timestamp('created_at')->nullable();
});
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE `${prefix}post_mentions_user` MODIFY created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP");
},
'down' => function (Builder $schema) {
$schema->table('post_mentions_user', function (Blueprint $table) {
$table->dropColumn('created_at');
});
}
];

View File

@ -0,0 +1,33 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed 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) {
$schema->table('tags', function (Blueprint $table) {
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
});
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE `${prefix}tags` MODIFY created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP");
$connection->statement("ALTER TABLE `${prefix}tags` MODIFY updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP");
},
'down' => function (Builder $schema) {
$schema->table('tags', function (Blueprint $table) {
$table->dropColumn('created_at');
$table->dropColumn('updated_at');
});
}
];

View File

@ -0,0 +1,30 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed 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) {
$schema->table('discussion_tag', function (Blueprint $table) {
$table->timestamp('created_at')->nullable();
});
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE `${prefix}discussion_tag` MODIFY created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP");
},
'down' => function (Builder $schema) {
$schema->table('discussion_tag', function (Blueprint $table) {
$table->dropColumn('created_at');
});
}
];

View File

@ -42,7 +42,12 @@ class Tag extends AbstractModel
protected $table = 'tags';
protected $dates = ['last_posted_at'];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['last_posted_at', 'created_at', 'updated_at'];
protected $casts = [
'is_hidden' => 'bool',

View File

@ -0,0 +1,33 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed 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) {
$schema->table('groups', function (Blueprint $table) {
$table->timestamp('created_at')->nullable();
$table->timestamp('updated_at')->nullable();
});
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE `${prefix}groups` MODIFY created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP");
$connection->statement("ALTER TABLE `${prefix}groups` MODIFY updated_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP");
},
'down' => function (Builder $schema) {
$schema->table('groups', function (Blueprint $table) {
$table->dropColumn('created_at');
$table->dropColumn('updated_at');
});
}
];

View File

@ -0,0 +1,30 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed 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) {
$schema->table('group_user', function (Blueprint $table) {
$table->timestamp('created_at')->nullable();
});
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE `${prefix}group_user` MODIFY created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP");
},
'down' => function (Builder $schema) {
$schema->table('group_user', function (Blueprint $table) {
$table->dropColumn('created_at');
});
}
];

View File

@ -0,0 +1,30 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed 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) {
$schema->table('group_permission', function (Blueprint $table) {
$table->timestamp('created_at')->nullable();
});
// do this manually because dbal doesn't recognize timestamp columns
$connection = $schema->getConnection();
$prefix = $connection->getTablePrefix();
$connection->statement("ALTER TABLE `${prefix}group_permission` MODIFY created_at TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP");
},
'down' => function (Builder $schema) {
$schema->table('group_permission', function (Blueprint $table) {
$table->dropColumn('created_at');
});
}
];

View File

@ -52,6 +52,13 @@ class Group extends AbstractModel
*/
const MODERATOR_ID = 4;
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['created_at', 'updated_at'];
/**
* Boot the model.
*

View File

@ -23,6 +23,13 @@ class Permission extends AbstractModel
*/
protected $table = 'group_permission';
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['created_at'];
/**
* Define the relationship with the group that this permission is for.
*