Skip to content

Commit

Permalink
Revert migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor committed Sep 21, 2024
1 parent bb0e8fc commit 863ec3c
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?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\Builder;

return [
'up' => function (Builder $schema) {
$emojioneToTwemojiMap = [
'1f468-2764-1f468' => '1f468-200d-2764-fe0f-200d-1f468',
'1f469-2764-1f469' => '1f469-200d-2764-fe0f-200d-1f469',
'1f468-2764-1f48b-1f468' => '1f468-200d-2764-fe0f-200d-1f48b-200d-1f468',
'1f469-2764-1f48b-1f469' => '1f469-200d-2764-fe0f-200d-1f48b-200d-1f469',
'1f468-1f468-1f466' => '1f468-200d-1f468-200d-1f466',
'1f468-1f468-1f466-1f466' => '1f468-200d-1f468-200d-1f466-200d-1f466',
'1f468-1f468-1f467' => '1f468-200d-1f468-200d-1f467',
'1f468-1f468-1f467-1f466' => '1f468-200d-1f468-200d-1f467-200d-1f466',
'1f468-1f468-1f467-1f467' => '1f468-200d-1f468-200d-1f467-200d-1f467',
'1f468-1f469-1f466-1f466' => '1f468-200d-1f469-200d-1f466-200d-1f466',
'1f468-1f469-1f467' => '1f468-200d-1f469-200d-1f467',
'1f468-1f469-1f467-1f466' => '1f468-200d-1f469-200d-1f467-200d-1f466',
'1f468-1f469-1f467-1f467' => '1f468-200d-1f469-200d-1f467-200d-1f467',
'1f469-1f469-1f466' => '1f469-200d-1f469-200d-1f466',
'1f469-1f469-1f466-1f466' => '1f469-200d-1f469-200d-1f466-200d-1f466',
'1f469-1f469-1f467' => '1f469-200d-1f469-200d-1f467',
'1f469-1f469-1f467-1f466' => '1f469-200d-1f469-200d-1f467-200d-1f466',
'1f469-1f469-1f467-1f467' => '1f469-200d-1f469-200d-1f467-200d-1f467',
'1f441-1f5e8' => '1f441-200d-1f5e8', // as always PITA
'1f3f3-1f308' => '1f3f3-fe0f-200d-1f308',

// https://github.com/twitter/twemoji/issues/192
'1f91d-1f3fb' => '1f91d',
'1f91d-1f3fc' => '1f91d',
'1f91d-1f3fd' => '1f91d',
'1f91d-1f3fe' => '1f91d',
'1f91d-1f3ff' => '1f91d',
'1f93c-1f3fb' => '1f93c',
'1f93c-1f3fc' => '1f93c',
'1f93c-1f3fd' => '1f93c',
'1f93c-1f3fe' => '1f93c',
'1f93c-1f3ff' => '1f93c',
];

$fromCodePoint = function ($code) {
$num = intval($code, 16);

if ($num <= 0x7F) {
return chr($num);
}

if ($num <= 0x7FF) {
return chr(($num >> 6) + 192).chr(($num & 63) + 128);
}

if ($num <= 0xFFFF) {
return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
}

return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
};

$convertEmojioneToTwemoji = function ($code) use ($emojioneToTwemojiMap) {
if (isset($emojioneToTwemojiMap[$code])) {
return $emojioneToTwemojiMap[$code];
}

return ltrim($code, '0');
};

$posts = $schema->getConnection()->table('posts')
->select('id', 'content')
->where('content', 'like', '%<EMOJI%')
->cursor();

foreach ($posts as $post) {
$content = preg_replace_callback(
'/<EMOJI seq="(.+?)">.+?<\/EMOJI>/',
function ($m) use ($convertEmojioneToTwemoji, $fromCodePoint) {
$code = $convertEmojioneToTwemoji($m[1]);
$codepoints = explode('-', $code);

return implode('', array_map($fromCodePoint, $codepoints));
},
$post->content
);

$schema->getConnection()->table('posts')
->where('id', $post->id)
->update(['content' => $content]);
}
},

'down' => function (Builder $schema) {
// not implemented
}
];
31 changes: 31 additions & 0 deletions framework/core/migrations/2018_09_15_041340_add_users_indicies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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('users', function (Blueprint $table) {
$table->index('joined_at');
$table->index('last_seen_at');
$table->index('discussion_count');
$table->index('comment_count');
});
},

'down' => function (Builder $schema) {
$schema->table('users', function (Blueprint $table) {
$table->dropIndex(['joined_at']);
$table->dropIndex(['last_seen_at']);
$table->dropIndex(['discussion_count']);
$table->dropIndex(['comment_count']);
});
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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('discussions', function (Blueprint $table) {
$table->index('last_posted_at');
$table->index('last_posted_user_id');
$table->index('created_at');
$table->index('user_id');
$table->index('comment_count');
$table->index('participant_count');
$table->index('hidden_at');
});
},

'down' => function (Builder $schema) {
$schema->table('discussions', function (Blueprint $table) {
$table->dropIndex(['last_posted_at']);
$table->dropIndex(['last_posted_user_id']);
$table->dropIndex(['created_at']);
$table->dropIndex(['user_id']);
$table->dropIndex(['comment_count']);
$table->dropIndex(['participant_count']);
$table->dropIndex(['hidden_at']);
});
}
];
4 changes: 2 additions & 2 deletions framework/core/migrations/mysql-install.dump
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ INSERT INTO `db_prefix_migrations` VALUES (49,'2018_01_18_135100_change_posts_ad
INSERT INTO `db_prefix_migrations` VALUES (50,'2018_01_30_112238_add_fulltext_index_to_discussions_title',NULL);
INSERT INTO `db_prefix_migrations` VALUES (51,'2018_01_30_220100_create_post_user_table',NULL);
INSERT INTO `db_prefix_migrations` VALUES (52,'2018_01_30_222900_change_users_rename_columns',NULL);
INSERT INTO `db_prefix_migrations` VALUES (55,'2018_09_15_041340_add_users_indices',NULL);
INSERT INTO `db_prefix_migrations` VALUES (56,'2018_09_15_041828_add_discussions_indices',NULL);
INSERT INTO `db_prefix_migrations` VALUES (55,'2018_09_15_041340_add_users_indicies',NULL);
INSERT INTO `db_prefix_migrations` VALUES (56,'2018_09_15_041828_add_discussions_indicies',NULL);
INSERT INTO `db_prefix_migrations` VALUES (57,'2018_09_15_043337_add_notifications_indices',NULL);
INSERT INTO `db_prefix_migrations` VALUES (58,'2018_09_15_043621_add_posts_indices',NULL);
INSERT INTO `db_prefix_migrations` VALUES (59,'2018_09_22_004100_change_registration_tokens_columns',NULL);
Expand Down
4 changes: 2 additions & 2 deletions framework/core/migrations/pgsql-install.dump
Original file line number Diff line number Diff line change
Expand Up @@ -1207,8 +1207,8 @@ INSERT INTO public.db_prefix_migrations VALUES (49,'2018_01_18_135100_change_pos
INSERT INTO public.db_prefix_migrations VALUES (50,'2018_01_30_112238_add_fulltext_index_to_discussions_title',NULL);
INSERT INTO public.db_prefix_migrations VALUES (51,'2018_01_30_220100_create_post_user_table',NULL);
INSERT INTO public.db_prefix_migrations VALUES (52,'2018_01_30_222900_change_users_rename_columns',NULL);
INSERT INTO public.db_prefix_migrations VALUES (55,'2018_09_15_041340_add_users_indices',NULL);
INSERT INTO public.db_prefix_migrations VALUES (56,'2018_09_15_041828_add_discussions_indices',NULL);
INSERT INTO public.db_prefix_migrations VALUES (55,'2018_09_15_041340_add_users_indicies',NULL);
INSERT INTO public.db_prefix_migrations VALUES (56,'2018_09_15_041828_add_discussions_indicies',NULL);
INSERT INTO public.db_prefix_migrations VALUES (57,'2018_09_15_043337_add_notifications_indices',NULL);
INSERT INTO public.db_prefix_migrations VALUES (58,'2018_09_15_043621_add_posts_indices',NULL);
INSERT INTO public.db_prefix_migrations VALUES (59,'2018_09_22_004100_change_registration_tokens_columns',NULL);
Expand Down
4 changes: 2 additions & 2 deletions framework/core/migrations/sqlite-install.dump
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ INSERT INTO db_prefix_migrations VALUES(49,'2018_01_18_135100_change_posts_add_f
INSERT INTO db_prefix_migrations VALUES(50,'2018_01_30_112238_add_fulltext_index_to_discussions_title',NULL);
INSERT INTO db_prefix_migrations VALUES(51,'2018_01_30_220100_create_post_user_table',NULL);
INSERT INTO db_prefix_migrations VALUES(52,'2018_01_30_222900_change_users_rename_columns',NULL);
INSERT INTO db_prefix_migrations VALUES(55,'2018_09_15_041340_add_users_indices',NULL);
INSERT INTO db_prefix_migrations VALUES(56,'2018_09_15_041828_add_discussions_indices',NULL);
INSERT INTO db_prefix_migrations VALUES(55,'2018_09_15_041340_add_users_indicies',NULL);
INSERT INTO db_prefix_migrations VALUES(56,'2018_09_15_041828_add_discussions_indicies',NULL);
INSERT INTO db_prefix_migrations VALUES(57,'2018_09_15_043337_add_notifications_indices',NULL);
INSERT INTO db_prefix_migrations VALUES(58,'2018_09_15_043621_add_posts_indices',NULL);
INSERT INTO db_prefix_migrations VALUES(59,'2018_09_22_004100_change_registration_tokens_columns',NULL);
Expand Down

0 comments on commit 863ec3c

Please sign in to comment.