diff --git a/extensions/mentions/migrations/2022_05_20_000005_add_created_at_to_post_mentions_post_table.php b/extensions/mentions/migrations/2022_05_20_000005_add_created_at_to_post_mentions_post_table.php new file mode 100644 index 000000000..1acd6988f --- /dev/null +++ b/extensions/mentions/migrations/2022_05_20_000005_add_created_at_to_post_mentions_post_table.php @@ -0,0 +1,30 @@ + 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'); + }); + } +]; diff --git a/extensions/mentions/migrations/2022_05_20_000006_add_created_at_to_post_mentions_user_table.php b/extensions/mentions/migrations/2022_05_20_000006_add_created_at_to_post_mentions_user_table.php new file mode 100644 index 000000000..0a1e2eb2a --- /dev/null +++ b/extensions/mentions/migrations/2022_05_20_000006_add_created_at_to_post_mentions_user_table.php @@ -0,0 +1,30 @@ + 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'); + }); + } +]; diff --git a/extensions/tags/migrations/2022_05_20_000003_add_timestamps_to_tags_table.php b/extensions/tags/migrations/2022_05_20_000003_add_timestamps_to_tags_table.php new file mode 100644 index 000000000..db96c2735 --- /dev/null +++ b/extensions/tags/migrations/2022_05_20_000003_add_timestamps_to_tags_table.php @@ -0,0 +1,33 @@ + 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'); + }); + } +]; diff --git a/extensions/tags/migrations/2022_05_20_000004_add_created_at_to_discussion_tag_table.php b/extensions/tags/migrations/2022_05_20_000004_add_created_at_to_discussion_tag_table.php new file mode 100644 index 000000000..eca2085f8 --- /dev/null +++ b/extensions/tags/migrations/2022_05_20_000004_add_created_at_to_discussion_tag_table.php @@ -0,0 +1,30 @@ + 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'); + }); + } +]; diff --git a/extensions/tags/src/Tag.php b/extensions/tags/src/Tag.php index b83460adf..202a54a1b 100644 --- a/extensions/tags/src/Tag.php +++ b/extensions/tags/src/Tag.php @@ -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', diff --git a/framework/core/migrations/2022_05_20_000000_add_timestamps_to_groups_table.php b/framework/core/migrations/2022_05_20_000000_add_timestamps_to_groups_table.php new file mode 100644 index 000000000..bab2b4a57 --- /dev/null +++ b/framework/core/migrations/2022_05_20_000000_add_timestamps_to_groups_table.php @@ -0,0 +1,33 @@ + 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'); + }); + } +]; diff --git a/framework/core/migrations/2022_05_20_000001_add_created_at_to_group_user_table.php b/framework/core/migrations/2022_05_20_000001_add_created_at_to_group_user_table.php new file mode 100644 index 000000000..36bf77265 --- /dev/null +++ b/framework/core/migrations/2022_05_20_000001_add_created_at_to_group_user_table.php @@ -0,0 +1,30 @@ + 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'); + }); + } +]; diff --git a/framework/core/migrations/2022_05_20_000002_add_created_at_to_group_permission_table.php b/framework/core/migrations/2022_05_20_000002_add_created_at_to_group_permission_table.php new file mode 100644 index 000000000..1333128f2 --- /dev/null +++ b/framework/core/migrations/2022_05_20_000002_add_created_at_to_group_permission_table.php @@ -0,0 +1,30 @@ + 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'); + }); + } +]; diff --git a/framework/core/src/Group/Group.php b/framework/core/src/Group/Group.php index b64a1ed26..6275a84c1 100644 --- a/framework/core/src/Group/Group.php +++ b/framework/core/src/Group/Group.php @@ -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. * diff --git a/framework/core/src/Group/Permission.php b/framework/core/src/Group/Permission.php index 7e5135a47..09ec03491 100644 --- a/framework/core/src/Group/Permission.php +++ b/framework/core/src/Group/Permission.php @@ -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. *