Replace go-migrate with morph (#19116)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c8198fbefe
Коммит
6595b31f23
@@ -26,7 +26,7 @@ jobs:
|
|||||||
cd ../
|
cd ../
|
||||||
git clone --depth=1 --no-single-branch https://github.com/mattermost/mattermost-webapp.git
|
git clone --depth=1 --no-single-branch https://github.com/mattermost/mattermost-webapp.git
|
||||||
cd mattermost-webapp
|
cd mattermost-webapp
|
||||||
git checkout $CIRCLE_BRANCH || git checkout master
|
git checkout $CIRCLE_BRANCH || git checkout release-6.0
|
||||||
export WEBAPP_GIT_COMMIT=$(git rev-parse HEAD)
|
export WEBAPP_GIT_COMMIT=$(git rev-parse HEAD)
|
||||||
echo "$WEBAPP_GIT_COMMIT"
|
echo "$WEBAPP_GIT_COMMIT"
|
||||||
|
|
||||||
@@ -537,18 +537,18 @@ workflows:
|
|||||||
- check-mattermost-vet
|
- check-mattermost-vet
|
||||||
- check-golangci-lint
|
- check-golangci-lint
|
||||||
- build-api-spec
|
- build-api-spec
|
||||||
- upload-s3-sha:
|
# - upload-s3-sha:
|
||||||
context: mattermost-ci-pr-builds-s3
|
# context: mattermost-ci-pr-builds-s3
|
||||||
requires:
|
# requires:
|
||||||
- build
|
# - build
|
||||||
- upload-s3:
|
# - upload-s3:
|
||||||
context: mattermost-ci-pr-builds-s3
|
# context: mattermost-ci-pr-builds-s3
|
||||||
requires:
|
# requires:
|
||||||
- build
|
# - build
|
||||||
- build-docker:
|
# - build-docker:
|
||||||
context: matterbuild-docker
|
# context: matterbuild-docker
|
||||||
requires:
|
# requires:
|
||||||
- upload-s3-sha
|
# - upload-s3-sha
|
||||||
- test:
|
- test:
|
||||||
name: test-mysql
|
name: test-mysql
|
||||||
dbdriver: mysql
|
dbdriver: mysql
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -292,7 +292,7 @@ new-migration: migration-prereqs ## Creates a new migration
|
|||||||
@echo "Generating new migration for postgres"
|
@echo "Generating new migration for postgres"
|
||||||
$(GOBIN)/migrate create -ext sql -dir db/migrations/postgres -seq $(name)
|
$(GOBIN)/migrate create -ext sql -dir db/migrations/postgres -seq $(name)
|
||||||
|
|
||||||
@echo "When you are done writing your migration, run 'make migrations'"
|
@echo "When you are done writing your migration, run 'make migrations-bindata'"
|
||||||
|
|
||||||
migrations-bindata: ## Generates bindata migrations
|
migrations-bindata: ## Generates bindata migrations
|
||||||
$(GO) get -modfile=go.tools.mod github.com/go-bindata/go-bindata/...
|
$(GO) get -modfile=go.tools.mod github.com/go-bindata/go-bindata/...
|
||||||
|
|||||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -1,3 +1,18 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Teams'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_teams_name'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_teams_name ON Teams(Name);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
SET @preparedStatement = (SELECT IF(
|
SET @preparedStatement = (SELECT IF(
|
||||||
(
|
(
|
||||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
|||||||
@@ -80,3 +80,18 @@ SET @preparedStatement = (SELECT IF(
|
|||||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
EXECUTE alterIfNotExists;
|
EXECUTE alterIfNotExists;
|
||||||
DEALLOCATE PREPARE alterIfNotExists;
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Teams'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_teams_name'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_teams_name ON Teams;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|||||||
@@ -1,3 +1,18 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'TeamMembers'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_teammembers_team_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_teammembers_team_id ON TeamMembers(TeamId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
SET @preparedStatement = (SELECT IF(
|
SET @preparedStatement = (SELECT IF(
|
||||||
(
|
(
|
||||||
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
|||||||
@@ -68,3 +68,18 @@ SET @preparedStatement = (SELECT IF(
|
|||||||
PREPARE alterIfNotExists FROM @preparedStatement;
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
EXECUTE alterIfNotExists;
|
EXECUTE alterIfNotExists;
|
||||||
DEALLOCATE PREPARE alterIfNotExists;
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'TeamMembers'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_teammembers_team_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_teammembers_team_id ON TeamMembers;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|||||||
1
db/migrations/mysql/000003_create_cluster_discovery.down.sql
Обычный файл
1
db/migrations/mysql/000003_create_cluster_discovery.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS ClusterDiscovery;
|
||||||
11
db/migrations/mysql/000003_create_cluster_discovery.up.sql
Обычный файл
11
db/migrations/mysql/000003_create_cluster_discovery.up.sql
Обычный файл
@@ -0,0 +1,11 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS ClusterDiscovery (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
Type varchar(64) DEFAULT NULL,
|
||||||
|
ClusterName varchar(64) DEFAULT NULL,
|
||||||
|
Hostname text,
|
||||||
|
GossipPort int(11) DEFAULT NULL,
|
||||||
|
Port integer DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
LastPingAt bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
1
db/migrations/mysql/000004_create_command_webhooks.down.sql
Обычный файл
1
db/migrations/mysql/000004_create_command_webhooks.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS CommandWebhooks;
|
||||||
12
db/migrations/mysql/000004_create_command_webhooks.up.sql
Обычный файл
12
db/migrations/mysql/000004_create_command_webhooks.up.sql
Обычный файл
@@ -0,0 +1,12 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS CommandWebhooks (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
CommandId varchar(26) DEFAULT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
ChannelId varchar(26) DEFAULT NULL,
|
||||||
|
RootId varchar(26) DEFAULT NULL,
|
||||||
|
ParentId varchar(26) DEFAULT NULL,
|
||||||
|
UseCount integer DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
KEY idx_command_webhook_create_at (CreateAt)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
1
db/migrations/mysql/000005_create_compliances.down.sql
Обычный файл
1
db/migrations/mysql/000005_create_compliances.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS Compliances;
|
||||||
14
db/migrations/mysql/000005_create_compliances.up.sql
Обычный файл
14
db/migrations/mysql/000005_create_compliances.up.sql
Обычный файл
@@ -0,0 +1,14 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Compliances (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreateAt bigint(20),
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
Status varchar(64) DEFAULT NULL,
|
||||||
|
Count integer DEFAULT NULL,
|
||||||
|
`Desc` text,
|
||||||
|
Type varchar(64) DEFAULT NULL,
|
||||||
|
StartAt bigint(20),
|
||||||
|
EndAt bigint(20),
|
||||||
|
Keywords text,
|
||||||
|
Emails text,
|
||||||
|
PRIMARY KEY (Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
16
db/migrations/mysql/000006_create_emojis.down.sql
Обычный файл
16
db/migrations/mysql/000006_create_emojis.down.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Emoji'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_emoji_name'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_emoji_name ON Emoji(Name);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Emoji;
|
||||||
73
db/migrations/mysql/000006_create_emojis.up.sql
Обычный файл
73
db/migrations/mysql/000006_create_emojis.up.sql
Обычный файл
@@ -0,0 +1,73 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Emoji (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
CreatorId varchar(26) DEFAULT NULL,
|
||||||
|
Name varchar(64) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
UNIQUE KEY (Name, DeleteAt),
|
||||||
|
KEY idx_emoji_update_at (UpdateAt),
|
||||||
|
KEY idx_emoji_create_at (CreateAt),
|
||||||
|
KEY idx_emoji_delete_at (DeleteAt)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.statistics
|
||||||
|
WHERE table_name = 'Emoji'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_emoji_create_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX ON Emoji(CreateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.statistics
|
||||||
|
WHERE table_name = 'Emoji'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_emoji_delete_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX ON Emoji(DeleteAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.statistics
|
||||||
|
WHERE table_name = 'Emoji'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_emoji_update_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX ON Emoji(UpdateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Emoji'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_emoji_name'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_emoji_name ON Emoji;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
1
db/migrations/mysql/000007_create_user_groups.down.sql
Обычный файл
1
db/migrations/mysql/000007_create_user_groups.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS UserGroups;
|
||||||
62
db/migrations/mysql/000007_create_user_groups.up.sql
Обычный файл
62
db/migrations/mysql/000007_create_user_groups.up.sql
Обычный файл
@@ -0,0 +1,62 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS UserGroups (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
Name varchar(64) DEFAULT NULL,
|
||||||
|
DisplayName varchar(128) DEFAULT NULL,
|
||||||
|
Description text,
|
||||||
|
Source varchar(64) DEFAULT NULL,
|
||||||
|
RemoteId varchar(48) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
AllowReference tinyint(1) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
UNIQUE KEY Name (Name),
|
||||||
|
UNIQUE KEY Source (Source, RemoteId),
|
||||||
|
KEY idx_usergroups_remote_id (RemoteId),
|
||||||
|
KEY idx_usergroups_delete_at (DeleteAt)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'UserGroups'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'AllowReference'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE UserGroups ADD AllowReference tinyint(1) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'UserGroups'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_usergroups_remote_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_usergroups_remote_id ON UserGroups(RemoteId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'UserGroups'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_usergroups_delete_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_usergroups_delete_at ON UserGroups(DeleteAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
1
db/migrations/mysql/000008_create_group_members.down.sql
Обычный файл
1
db/migrations/mysql/000008_create_group_members.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS GroupMembers;
|
||||||
23
db/migrations/mysql/000008_create_group_members.up.sql
Обычный файл
23
db/migrations/mysql/000008_create_group_members.up.sql
Обычный файл
@@ -0,0 +1,23 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS GroupMembers (
|
||||||
|
GroupId varchar(26) NOT NULL,
|
||||||
|
UserId varchar(26) NOT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (GroupId, UserId),
|
||||||
|
KEY idx_groupmembers_create_at (CreateAt)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'GroupMembers'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_groupmembers_create_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_groupmembers_create_at ON GroupMembers(CreateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
1
db/migrations/mysql/000009_create_group_teams.down.sql
Обычный файл
1
db/migrations/mysql/000009_create_group_teams.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS GroupTeams;
|
||||||
55
db/migrations/mysql/000009_create_group_teams.up.sql
Обычный файл
55
db/migrations/mysql/000009_create_group_teams.up.sql
Обычный файл
@@ -0,0 +1,55 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS GroupTeams (
|
||||||
|
GroupId varchar(26) NOT NULL,
|
||||||
|
AutoAdd tinyint(1),
|
||||||
|
SchemeAdmin tinyint(1) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
TeamId varchar(26) NOT NULL,
|
||||||
|
PRIMARY KEY (GroupId, TeamId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'GroupTeams'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'SchemeAdmin'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE GroupTeams ADD COLUMN SchemeAdmin tinyint(1) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'GroupTeams'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_groupteams_schemeadmin'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_groupteams_schemeadmin ON GroupTeams(SchemeAdmin);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'GroupTeams'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_groupteams_teamid'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_groupteams_teamid ON GroupTeams(TeamId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
1
db/migrations/mysql/000010_create_group_channels.down.sql
Обычный файл
1
db/migrations/mysql/000010_create_group_channels.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS GroupChannels;
|
||||||
57
db/migrations/mysql/000010_create_group_channels.up.sql
Обычный файл
57
db/migrations/mysql/000010_create_group_channels.up.sql
Обычный файл
@@ -0,0 +1,57 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS GroupChannels (
|
||||||
|
GroupId varchar(26) NOT NULL,
|
||||||
|
AutoAdd tinyint(1),
|
||||||
|
SchemeAdmin tinyint(1) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
ChannelId varchar(26) NOT NULL,
|
||||||
|
PRIMARY KEY (GroupId, ChannelId),
|
||||||
|
KEY idx_groupchannels_schemeadmin (SchemeAdmin),
|
||||||
|
KEY idx_groupchannels_channelid (ChannelId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'GroupChannels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_groupchannels_channelid'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_groupchannels_channelid ON GroupChannels (ChannelId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'GroupChannels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_groupchannels_schemeadmin'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_groupchannels_schemeadmin ON GroupChannels(ScemeAdmin);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'GroupChannels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'SchemeAdmin'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE GroupChannels ADD COLUMN ScemeAdmin tinyint(1);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createColumnIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createColumnIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createColumnIfNotExists;
|
||||||
1
db/migrations/mysql/000011_create_link_metadata.down.sql
Обычный файл
1
db/migrations/mysql/000011_create_link_metadata.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS LinkMetadata;
|
||||||
9
db/migrations/mysql/000011_create_link_metadata.up.sql
Обычный файл
9
db/migrations/mysql/000011_create_link_metadata.up.sql
Обычный файл
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS LinkMetadata (
|
||||||
|
Hash bigint(20) NOT NULL,
|
||||||
|
URL text,
|
||||||
|
Timestamp bigint(20) DEFAULT NULL,
|
||||||
|
Type varchar(16) DEFAULT NULL,
|
||||||
|
Data text,
|
||||||
|
PRIMARY KEY (Hash),
|
||||||
|
KEY idx_link_metadata_url_timestamp (URL(512),Timestamp)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
16
db/migrations/mysql/000012_create_commands.down.sql
Обычный файл
16
db/migrations/mysql/000012_create_commands.down.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Commands'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'PluginId'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Commands DROP COLUMN PluginId;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Commands;
|
||||||
41
db/migrations/mysql/000012_create_commands.up.sql
Обычный файл
41
db/migrations/mysql/000012_create_commands.up.sql
Обычный файл
@@ -0,0 +1,41 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Commands (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
Token varchar(26) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
CreatorId varchar(26) DEFAULT NULL,
|
||||||
|
TeamId varchar(26) DEFAULT NULL,
|
||||||
|
`Trigger` varchar(128) DEFAULT NULL,
|
||||||
|
Method varchar(1) DEFAULT NULL,
|
||||||
|
Username varchar(64) DEFAULT NULL,
|
||||||
|
IconURL text,
|
||||||
|
AutoComplete tinyint(1) DEFAULT NULL,
|
||||||
|
AutoCompleteDesc text,
|
||||||
|
AutoCompleteHint text,
|
||||||
|
DisplayName varchar(64) DEFAULT NULL,
|
||||||
|
Description varchar(128) DEFAULT NULL,
|
||||||
|
URL text,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
KEY idx_command_team_id (TeamId),
|
||||||
|
KEY idx_command_update_at (UpdateAt),
|
||||||
|
KEY idx_command_create_at (CreateAt),
|
||||||
|
KEY idx_command_delete_at (DeleteAt)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Commands'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'PluginId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Commands ADD PluginId varchar(190);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
UPDATE Commands SET PluginId = '' WHERE PluginId IS NULL;
|
||||||
1
db/migrations/mysql/000013_create_incoming_webhooks.down.sql
Обычный файл
1
db/migrations/mysql/000013_create_incoming_webhooks.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS IncomingWebhooks;
|
||||||
176
db/migrations/mysql/000013_create_incoming_webhooks.up.sql
Обычный файл
176
db/migrations/mysql/000013_create_incoming_webhooks.up.sql
Обычный файл
@@ -0,0 +1,176 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS IncomingWebhooks (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
ChannelId varchar(26) DEFAULT NULL,
|
||||||
|
TeamId varchar(26) DEFAULT NULL,
|
||||||
|
DisplayName varchar(64) DEFAULT NULL,
|
||||||
|
Description varchar(128) DEFAULT NULL,
|
||||||
|
Username varchar(64) DEFAULT NULL,
|
||||||
|
PRIMARY KEY(Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'IncomingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Username'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE IncomingWebhooks MODIFY Username VARCHAR(255);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'IncomingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'IconURL'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE IncomingWebhooks ADD IconURL text;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'IncomingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ChannelLocked'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE IncomingWebhooks ADD ChannelLocked tinyint(1) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'IncomingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Description'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE IncomingWebhooks MODIFY Description TEXT;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'IncomingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_incoming_webhook_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_incoming_webhook_user_id ON IncomingWebhooks (UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'IncomingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_incoming_webhook_team_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_incoming_webhook_team_id ON IncomingWebhooks (TeamId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'IncomingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_incoming_webhook_update_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_incoming_webhook_update_at ON IncomingWebhooks (UpdateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'IncomingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_incoming_webhook_create_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_incoming_webhook_create_at ON IncomingWebhooks (CreateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'IncomingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_incoming_webhook_delete_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_incoming_webhook_delete_at ON IncomingWebhooks (DeleteAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
CREATE PROCEDURE CheckColumnMaxLength(
|
||||||
|
in columnName varchar(45),
|
||||||
|
in threshold int )
|
||||||
|
BEGIN
|
||||||
|
DECLARE C INT;
|
||||||
|
|
||||||
|
SELECT COALESCE(
|
||||||
|
SUM(
|
||||||
|
CASE
|
||||||
|
WHEN CHAR_LENGTH(columnName) > threshold THEN 1
|
||||||
|
ELSE 0
|
||||||
|
END
|
||||||
|
),
|
||||||
|
0) INTO C
|
||||||
|
FROM IncomingWebhooks;
|
||||||
|
|
||||||
|
IF(C > 0) THEN
|
||||||
|
SET @messageText = CONCAT('IncomingWebhooks column ', columnName, ' has data larger that ', threshold, ' characters');
|
||||||
|
SIGNAL SQLSTATE '45000'
|
||||||
|
SET MESSAGE_TEXT = @messageText;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
|
||||||
|
CALL CheckColumnMaxLength('Username', 255);
|
||||||
|
CALL CheckColumnMaxLength('IconURL', 1024);
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS CheckColumnMaxLength;
|
||||||
1
db/migrations/mysql/000014_create_outgoing_webhooks.down.sql
Обычный файл
1
db/migrations/mysql/000014_create_outgoing_webhooks.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS OutgoingWebhooks;
|
||||||
149
db/migrations/mysql/000014_create_outgoing_webhooks.up.sql
Обычный файл
149
db/migrations/mysql/000014_create_outgoing_webhooks.up.sql
Обычный файл
@@ -0,0 +1,149 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS OutgoingWebhooks (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
Token varchar(26) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
CreatorId varchar(26) DEFAULT NULL,
|
||||||
|
ChannelId varchar(26) DEFAULT NULL,
|
||||||
|
TeamId varchar(26) DEFAULT NULL,
|
||||||
|
TriggerWords text,
|
||||||
|
CallbackURLs text,
|
||||||
|
DisplayName varchar(64) DEFAULT NULL,
|
||||||
|
PRIMARY KEY(Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OutgoingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ContentType'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OutgoingWebhooks ADD ContentType VARCHAR(128);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OutgoingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'TriggerWhen'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OutgoingWebhooks ADD TriggerWhen int(11) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OutgoingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Username'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OutgoingWebhooks ADD Username VARCHAR(64) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OutgoingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'IconURL'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OutgoingWebhooks ADD IconURL text;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OutgoingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Description'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OutgoingWebhooks ADD Description text;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'OutgoingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_outgoing_webhook_team_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_outgoing_webhook_team_id ON OutgoingWebhooks (TeamId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'OutgoingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_outgoing_webhook_update_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_outgoing_webhook_update_at ON OutgoingWebhooks (UpdateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'OutgoingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_outgoing_webhook_create_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_outgoing_webhook_create_at ON OutgoingWebhooks (CreateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'OutgoingWebhooks'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_outgoing_webhook_delete_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_outgoing_webhook_delete_at ON OutgoingWebhooks (DeleteAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
1
db/migrations/mysql/000015_create_systems.down.sql
Обычный файл
1
db/migrations/mysql/000015_create_systems.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS Systems;
|
||||||
5
db/migrations/mysql/000015_create_systems.up.sql
Обычный файл
5
db/migrations/mysql/000015_create_systems.up.sql
Обычный файл
@@ -0,0 +1,5 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Systems (
|
||||||
|
Name VARCHAR(64) NOT NULL,
|
||||||
|
Value text,
|
||||||
|
PRIMARY KEY (Name)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
1
db/migrations/mysql/000016_create_reactions.down.sql
Обычный файл
1
db/migrations/mysql/000016_create_reactions.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS Reactions;
|
||||||
76
db/migrations/mysql/000016_create_reactions.up.sql
Обычный файл
76
db/migrations/mysql/000016_create_reactions.up.sql
Обычный файл
@@ -0,0 +1,76 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Reactions (
|
||||||
|
UserId varchar(26) NOT NULL,
|
||||||
|
PostId varchar(26) NOT NULL,
|
||||||
|
EmojiName varchar(64) NOT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Reactions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'UpdateAt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Reactions ADD COLUMN UpdateAt bigint(20);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Reactions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'DeleteAt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Reactions ADD COLUMN DeleteAt bigint(20);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
CREATE PROCEDURE AlterPrimaryKey()
|
||||||
|
BEGIN
|
||||||
|
DECLARE existingPK varchar(26) default '';
|
||||||
|
|
||||||
|
SELECT IFNULL(GROUP_CONCAT(column_name ORDER BY seq_in_index), '') INTO existingPK
|
||||||
|
FROM information_schema.statistics
|
||||||
|
WHERE table_schema = DATABASE()
|
||||||
|
AND table_name = 'Reactions'
|
||||||
|
AND index_name = 'PRIMARY'
|
||||||
|
GROUP BY index_name;
|
||||||
|
|
||||||
|
IF existingPK != 'PostId,UserId,EmojiName' THEN
|
||||||
|
IF existingPk != '' THEN
|
||||||
|
ALTER TABLE Reactions DROP PRIMARY KEY;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
ALTER TABLE Reactions ADD PRIMARY KEY (PostId, UserID, EmojiName);
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
|
||||||
|
CALL AlterPrimaryKey();
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS AlterPrimaryKey;
|
||||||
|
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Reactions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'RemoteId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Reactions ADD COLUMN RemoteId varchar(26);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
1
db/migrations/mysql/000017_create_roles.down.sql
Обычный файл
1
db/migrations/mysql/000017_create_roles.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS Roles;
|
||||||
46
db/migrations/mysql/000017_create_roles.up.sql
Обычный файл
46
db/migrations/mysql/000017_create_roles.up.sql
Обычный файл
@@ -0,0 +1,46 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Roles (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
Name varchar(64) DEFAULT NULL,
|
||||||
|
DisplayName varchar(128) DEFAULT NULL,
|
||||||
|
Description text,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
Permissions text,
|
||||||
|
SchemeManaged tinyint(1) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
UNIQUE KEY Name (Name)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Roles'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'BuiltIn'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Roles ADD BuiltIn tinyint(1) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
UPDATE Roles SET SchemeManaged = 0
|
||||||
|
WHERE Name NOT IN ('system_user', 'system_admin', 'team_user', 'team_admin', 'channel_user', 'channel_admin');
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Roles'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Permissions'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Roles MODIFY Permissions longtext;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
1
db/migrations/mysql/000018_create_schemes.down.sql
Обычный файл
1
db/migrations/mysql/000018_create_schemes.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS Schemes;
|
||||||
121
db/migrations/mysql/000018_create_schemes.up.sql
Обычный файл
121
db/migrations/mysql/000018_create_schemes.up.sql
Обычный файл
@@ -0,0 +1,121 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Schemes (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
Name varchar(64) DEFAULT NULL,
|
||||||
|
DisplayName varchar(128) DEFAULT NULL,
|
||||||
|
Description text,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
Scope varchar(32) DEFAULT NULL,
|
||||||
|
DefaultTeamAdminRole varchar(64) DEFAULT NULL,
|
||||||
|
DefaultTeamUserRole varchar(64) DEFAULT NULL,
|
||||||
|
DefaultChannelAdminRole varchar(64) DEFAULT NULL,
|
||||||
|
DefaultChannelUserRole varchar(64) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
UNIQUE KEY Name (Name)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Schemes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'DefaultTeamGuestRole'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Schemes ADD DefaultTeamGuestRole varchar(64);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Schemes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'DefaultChannelGuestRole'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Schemes ADD DefaultChannelGuestRole varchar(64);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Schemes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'DefaultTeamGuestRole'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Schemes MODIFY DefaultTeamGuestRole varchar(64);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Schemes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'DefaultChannelGuestRole'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Schemes MODIFY DefaultChannelGuestRole varchar(64);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Schemes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_schemes_channel_guest_role'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_schemes_channel_guest_role ON Schemes(DefaultChannelGuestRole);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Schemes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_schemes_channel_user_role'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_schemes_channel_user_role ON Schemes(DefaultChannelUserRole);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Schemes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_schemes_channel_admin_role'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_schemes_channel_admin_role ON Schemes(DefaultChannelAdminRole);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
1
db/migrations/mysql/000019_create_licenses.down.sql
Обычный файл
1
db/migrations/mysql/000019_create_licenses.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS Licenses;
|
||||||
6
db/migrations/mysql/000019_create_licenses.up.sql
Обычный файл
6
db/migrations/mysql/000019_create_licenses.up.sql
Обычный файл
@@ -0,0 +1,6 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Licenses (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
Bytes text,
|
||||||
|
PRIMARY KEY (Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
16
db/migrations/mysql/000020_create_posts.down.sql
Обычный файл
16
db/migrations/mysql/000020_create_posts.down.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_channel_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_posts_channel_id ON Posts(ChannelId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Posts;
|
||||||
257
db/migrations/mysql/000020_create_posts.up.sql
Обычный файл
257
db/migrations/mysql/000020_create_posts.up.sql
Обычный файл
@@ -0,0 +1,257 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Posts (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
ChannelId varchar(26) DEFAULT NULL,
|
||||||
|
RootId varchar(26) DEFAULT NULL,
|
||||||
|
ParentId varchar(26) DEFAULT NULL,
|
||||||
|
OriginalId varchar(26) DEFAULT NULL,
|
||||||
|
Message text,
|
||||||
|
Type varchar(26) DEFAULT NULL,
|
||||||
|
Props text,
|
||||||
|
Hashtags text,
|
||||||
|
Filenames text,
|
||||||
|
PRIMARY KEY (Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'FileIds'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Posts ADD FileIds text;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'HasReactions'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Posts ADD HasReactions tinyint(1) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'EditAt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Posts ADD EditAt bigint(20) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'IsPinned'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Posts ADD IsPinned tinyint(1) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_update_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_posts_update_at ON Posts (UpdateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_create_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_posts_create_at ON Posts(CreateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_delete_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_posts_delete_at ON Posts(DeleteAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_root_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_posts_root_id ON Posts(RootId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_posts_user_id ON Posts(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_is_pinned'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_posts_is_pinned ON Posts(IsPinned);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_channel_id_update_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_posts_channel_id_update_at ON Posts(ChannelId, UpdateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_channel_id_delete_at_create_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_posts_channel_id_delete_at_create_at ON Posts(ChannelId, DeleteAt, CreateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_message_txt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE FULLTEXT INDEX idx_posts_message_txt ON Posts(Message);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_hashtags_txt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE FULLTEXT INDEX idx_posts_hashtags_txt ON Posts(Hashtags);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'RemoteId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Posts ADD RemoteId varchar(26);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Posts'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_posts_channel_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_posts_channel_id ON Posts;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ProductNoticeViewState'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_notice_views_user_notice'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_notice_views_user_notice ON ProductNoticeViewState(UserId, NoticeId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ProductNoticeViewState'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_notice_views_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_notice_views_user_id ON ProductNoticeViewState(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS ProductNoticeViewState;
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS ProductNoticeViewState (
|
||||||
|
UserId VARCHAR(26) NOT NULL,
|
||||||
|
NoticeId VARCHAR(26) NOT NULL,
|
||||||
|
Viewed int(11),
|
||||||
|
Timestamp bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (UserId, NoticeId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ProductNoticeViewState'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_notice_views_timestamp'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_notice_views_timestamp ON ProductNoticeViewState (Timestamp);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ProductNoticeViewState'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_notice_views_notice_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_notice_views_notice_id ON ProductNoticeViewState (NoticeId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ProductNoticeViewState'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_notice_views_user_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_notice_views_user_id ON ProductNoticeViewState;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ProductNoticeViewState'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_notice_views_user_notice'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_notice_views_user_notice ON ProductNoticeViewState;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
1
db/migrations/mysql/000022_create_sessions.down.sql
Обычный файл
1
db/migrations/mysql/000022_create_sessions.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS Sessions;
|
||||||
101
db/migrations/mysql/000022_create_sessions.up.sql
Обычный файл
101
db/migrations/mysql/000022_create_sessions.up.sql
Обычный файл
@@ -0,0 +1,101 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Sessions (
|
||||||
|
Id varchar(26) PRIMARY KEY,
|
||||||
|
Token varchar(26) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
ExpiresAt bigint(20) DEFAULT NULL,
|
||||||
|
LastActivityAt bigint(20) DEFAULT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
DeviceId text,
|
||||||
|
Roles varchar(64) DEFAULT NULL,
|
||||||
|
IsOAuth tinyint(1),
|
||||||
|
Props text
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Sessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ExpiredNotify'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Sessions ADD ExpiredNotify tinyint(1) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Sessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_sessions_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_sessions_user_id ON Sessions(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Sessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_sessions_token'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_sessions_token ON Sessions(Token);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Sessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_sessions_expires_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_sessions_expires_at ON Sessions(ExpiresAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Sessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_sessions_create_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_sessions_create_at ON Sessions(CreateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Sessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_sessions_last_activity_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_sessions_last_activity_at ON Sessions(LastActivityAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
DELETE FROM Sessions where ExpiresAt > 3000000000000;
|
||||||
1
db/migrations/mysql/000023_create_terms_of_service.down.sql
Обычный файл
1
db/migrations/mysql/000023_create_terms_of_service.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS TermsOfService;
|
||||||
7
db/migrations/mysql/000023_create_terms_of_service.up.sql
Обычный файл
7
db/migrations/mysql/000023_create_terms_of_service.up.sql
Обычный файл
@@ -0,0 +1,7 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS TermsOfService (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
Text text,
|
||||||
|
PRIMARY KEY (Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
1
db/migrations/mysql/000024_create_audits.down.sql
Обычный файл
1
db/migrations/mysql/000024_create_audits.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS Audits;
|
||||||
25
db/migrations/mysql/000024_create_audits.up.sql
Обычный файл
25
db/migrations/mysql/000024_create_audits.up.sql
Обычный файл
@@ -0,0 +1,25 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Audits (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
Action text,
|
||||||
|
ExtraInfo text,
|
||||||
|
IpAddress varchar(64) DEFAULT NULL,
|
||||||
|
SessionId varchar(26) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Audits'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_audits_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_audits_user_id ON Audits(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
16
db/migrations/mysql/000025_create_oauth_access_data.down.sql
Обычный файл
16
db/migrations/mysql/000025_create_oauth_access_data.down.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_oauthaccessdata_client_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_oauthaccessdata_client_id ON OAuthAccessData(ClientId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS OAuthAccessData;
|
||||||
159
db/migrations/mysql/000025_create_oauth_access_data.up.sql
Обычный файл
159
db/migrations/mysql/000025_create_oauth_access_data.up.sql
Обычный файл
@@ -0,0 +1,159 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS OAuthAccessData (
|
||||||
|
Token varchar(26) NOT NULL,
|
||||||
|
RefreshToken varchar(26) DEFAULT NULL,
|
||||||
|
RedirectUri text,
|
||||||
|
ClientId varchar(26) DEFAULT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Token),
|
||||||
|
UNIQUE KEY (ClientId, UserId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ClientId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OAuthAccessData ADD ClientId varchar(26) DEFAULT "";'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'UserId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OAuthAccessData ADD UserId varchar(26) DEFAULT "";'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.statistics
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_oauthaccessdata_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_oauthaccessdata_user_id ON OAuthAccessData(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ExpiresAt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OAuthAccessData ADD ExpiresAt bigint(20) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.statistics
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_oauthaccessdata_auth_code'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_oauthaccessdata_auth_code ON OAuthAccessData;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'AuthCode'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE OAuthAccessData DROP COLUMN AuthCode;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Scope'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OAuthAccessData ADD Scope varchar(128) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.statistics
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'ClientId_2'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX ClientId_2 ON OAuthAccessData;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.statistics
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_oauthaccessdata_refresh_token'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_oauthaccessdata_refresh_token ON OAuthAccessData(RefreshToken);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'OAuthAccessData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_oauthaccessdata_client_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_oauthaccessdata_client_id ON OAuthAccessData;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
16
db/migrations/mysql/000026_create_preferences.down.sql
Обычный файл
16
db/migrations/mysql/000026_create_preferences.down.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Preferences'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_preferences_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_preferences_user_id ON Preferences(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Preferences;
|
||||||
106
db/migrations/mysql/000026_create_preferences.up.sql
Обычный файл
106
db/migrations/mysql/000026_create_preferences.up.sql
Обычный файл
@@ -0,0 +1,106 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Preferences (
|
||||||
|
UserId varchar(26) NOT NULL,
|
||||||
|
Category varchar(32) NOT NULL,
|
||||||
|
Name varchar(32) NOT NULL,
|
||||||
|
Value text,
|
||||||
|
PRIMARY KEY (UserId, Category, Name)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Preferences'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Value'
|
||||||
|
AND data_type != 'text'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Preferences MODIFY Value text;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Preferences'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_preferences_category'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_preferences_category ON Preferences(Category);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Preferences'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_preferences_name'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_preferences_name ON Preferences(Name);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
CREATE PROCEDURE RenameSolarizedThemeWithUnderscore()
|
||||||
|
BEGIN
|
||||||
|
DECLARE finished INTEGER DEFAULT 0;
|
||||||
|
DECLARE curUserId VARCHAR(26);
|
||||||
|
DECLARE curName VARCHAR(32);
|
||||||
|
DECLARE curValue text;
|
||||||
|
|
||||||
|
DECLARE preference
|
||||||
|
CURSOR FOR
|
||||||
|
SELECT UserId, Name, Value
|
||||||
|
FROM Preferences
|
||||||
|
WHERE Category = 'theme' AND Value LIKE '%solarized_%';
|
||||||
|
|
||||||
|
-- declare NOT FOUND handler
|
||||||
|
DECLARE CONTINUE HANDLER
|
||||||
|
FOR NOT FOUND SET finished = 1;
|
||||||
|
|
||||||
|
OPEN preference;
|
||||||
|
|
||||||
|
getPreference: LOOP
|
||||||
|
FETCH preference INTO curUserId, curName, curValue;
|
||||||
|
IF finished = 1 THEN
|
||||||
|
LEAVE getPreference;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
-- update affected rows
|
||||||
|
UPDATE Preferences
|
||||||
|
SET Value = replace(curValue, 'solaraized_', 'solarized-')
|
||||||
|
WHERE Category = 'theme'
|
||||||
|
AND UserId = curUserId
|
||||||
|
AND Name = curName;
|
||||||
|
END LOOP getPreference;
|
||||||
|
END;
|
||||||
|
|
||||||
|
CALL RenameSolarizedThemeWithUnderscore();
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS RenameSolarizedThemeWithUnderscore;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Preferences'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_preferences_user_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_preferences_user_id ON Preferences;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
16
db/migrations/mysql/000027_create_status.down.sql
Обычный файл
16
db/migrations/mysql/000027_create_status.down.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Status'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_status_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_status_user_id ON Status(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Status;
|
||||||
83
db/migrations/mysql/000027_create_status.up.sql
Обычный файл
83
db/migrations/mysql/000027_create_status.up.sql
Обычный файл
@@ -0,0 +1,83 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Status (
|
||||||
|
UserId varchar(26) NOT NULL,
|
||||||
|
Status varchar(32) DEFAULT NULL,
|
||||||
|
Manual tinyint(1) DEFAULT NULL,
|
||||||
|
LastActivityAt bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (UserId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Status'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ActiveChannel'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Status DROP COLUMN ActiveChannel;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Status'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_status_status'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_status_status ON Status(Status);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Status'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'DNDEndTime'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Status ADD COLUMN DNDEndTime BIGINT;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Status'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'PrevStatus'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Status ADD COLUMN PrevStatus VARCHAR(32);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Status'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_status_user_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_status_user_id ON Status;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
1
db/migrations/mysql/000028_create_tokens.down.sql
Обычный файл
1
db/migrations/mysql/000028_create_tokens.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS Tokens;
|
||||||
23
db/migrations/mysql/000028_create_tokens.up.sql
Обычный файл
23
db/migrations/mysql/000028_create_tokens.up.sql
Обычный файл
@@ -0,0 +1,23 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Tokens (
|
||||||
|
Token varchar(64) NOT NULL,
|
||||||
|
CreateAt bigint(20),
|
||||||
|
Type varchar(64) DEFAULT NULL,
|
||||||
|
Extra text,
|
||||||
|
PRIMARY KEY (Token)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Tokens'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Extra'
|
||||||
|
AND data_type != 'text'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Tokens MODIFY Extra text;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
16
db/migrations/mysql/000029_create_bots.down.sql
Обычный файл
16
db/migrations/mysql/000029_create_bots.down.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Bots'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'LastIconUpdate'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Bots DROP COLUMN LastIconUpdate;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS bots;
|
||||||
24
db/migrations/mysql/000029_create_bots.up.sql
Обычный файл
24
db/migrations/mysql/000029_create_bots.up.sql
Обычный файл
@@ -0,0 +1,24 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Bots (
|
||||||
|
UserId varchar(26) NOT NULL,
|
||||||
|
Description text,
|
||||||
|
OwnerId varchar(190) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (UserId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Bots'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'LastIconUpdate'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Bots ADD LastIconUpdate bigint;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
16
db/migrations/mysql/000030_create_user_access_tokens.down.sql
Обычный файл
16
db/migrations/mysql/000030_create_user_access_tokens.down.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'UserAccessTokens'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_user_access_tokens_token'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_user_access_tokens_token ON UserAccessTokens(Token);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS UserAccessTokens;
|
||||||
53
db/migrations/mysql/000030_create_user_access_tokens.up.sql
Обычный файл
53
db/migrations/mysql/000030_create_user_access_tokens.up.sql
Обычный файл
@@ -0,0 +1,53 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS UserAccessTokens (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
Token varchar(26) DEFAULT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
Description text,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
UNIQUE (Token)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'UserAccessTokens'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'IsActive'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE UserAccessTokens ADD COLUMN IsActive tinyint(1) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterNotIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterNotIfExists;
|
||||||
|
DEALLOCATE PREPARE alterNotIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'UserAccessTokens'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_user_access_tokens_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_user_access_tokens_user_id ON UserAccessTokens(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'UserAccessTokens'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_user_access_tokens_token'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_user_access_tokens_token ON UserAccessTokens;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
1
db/migrations/mysql/000031_create_remote_clusters.down.sql
Обычный файл
1
db/migrations/mysql/000031_create_remote_clusters.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS RemoteClusters;
|
||||||
29
db/migrations/mysql/000031_create_remote_clusters.up.sql
Обычный файл
29
db/migrations/mysql/000031_create_remote_clusters.up.sql
Обычный файл
@@ -0,0 +1,29 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS RemoteClusters (
|
||||||
|
RemoteId VARCHAR(26) NOT NULL,
|
||||||
|
RemoteTeamId VARCHAR(26),
|
||||||
|
Name VARCHAR(64) NOT NULL,
|
||||||
|
DisplayName VARCHAR(64),
|
||||||
|
SiteURL text,
|
||||||
|
CreateAt bigint,
|
||||||
|
LastPingAt bigint,
|
||||||
|
Token VARCHAR(26) DEFAULT NULL,
|
||||||
|
RemoteToken VARCHAR(26),
|
||||||
|
Topics text,
|
||||||
|
CreatorId VARCHAR(26) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (RemoteId, Name)
|
||||||
|
);
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'RemoteClusters'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'remote_clusters_site_url_unique'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE UNIQUE INDEX remote_clusters_site_url_unique ON RemoteClusters (RemoteTeamId, SiteURL (168));'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
1
db/migrations/mysql/000032_create_sharedchannels.down.sql
Обычный файл
1
db/migrations/mysql/000032_create_sharedchannels.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS SharedChannels;
|
||||||
16
db/migrations/mysql/000032_create_sharedchannels.up.sql
Обычный файл
16
db/migrations/mysql/000032_create_sharedchannels.up.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS SharedChannels (
|
||||||
|
ChannelId varchar(26) NOT NULL,
|
||||||
|
TeamId varchar(26) DEFAULT NULL,
|
||||||
|
Home tinyint(1) DEFAULT NULL,
|
||||||
|
ReadOnly tinyint(1) DEFAULT NULL,
|
||||||
|
ShareName varchar(64) DEFAULT NULL,
|
||||||
|
ShareDisplayName varchar(64) DEFAULT NULL,
|
||||||
|
SharePurpose varchar(250) DEFAULT NULL,
|
||||||
|
ShareHeader text,
|
||||||
|
CreatorId varchar(26) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
RemoteId varchar(26) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (ChannelId),
|
||||||
|
UNIQUE KEY ShareName (ShareName, TeamId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
17
db/migrations/mysql/000033_create_sidebar_channels.down.sql
Обычный файл
17
db/migrations/mysql/000033_create_sidebar_channels.down.sql
Обычный файл
@@ -0,0 +1,17 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SidebarChannels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'CategoryId'
|
||||||
|
AND column_type != 'varchar(26)'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE SidebarChannels MODIFY CategoryId varchar(26);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS SidebarChannels;
|
||||||
23
db/migrations/mysql/000033_create_sidebar_channels.up.sql
Обычный файл
23
db/migrations/mysql/000033_create_sidebar_channels.up.sql
Обычный файл
@@ -0,0 +1,23 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS SidebarChannels (
|
||||||
|
ChannelId varchar(26) NOT NULL,
|
||||||
|
UserId varchar(26) NOT NULL,
|
||||||
|
CategoryId varchar(26) NOT NULL,
|
||||||
|
SortOrder bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (ChannelId, UserId, CategoryId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SidebarChannels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'CategoryId'
|
||||||
|
AND column_type != 'varchar(128)'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE SidebarChannels MODIFY CategoryId varchar(128);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
16
db/migrations/mysql/000034_create_oauthauthdata.down.sql
Обычный файл
16
db/migrations/mysql/000034_create_oauthauthdata.down.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'OAuthAuthData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_oauthauthdata_client_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_oauthauthdata_client_id ON OAuthAuthData(Code);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS OAuthAuthData;
|
||||||
38
db/migrations/mysql/000034_create_oauthauthdata.up.sql
Обычный файл
38
db/migrations/mysql/000034_create_oauthauthdata.up.sql
Обычный файл
@@ -0,0 +1,38 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS OAuthAuthData (
|
||||||
|
ClientId varchar(26) DEFAULT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
Code varchar(128) NOT NULL,
|
||||||
|
ExpiresIn int(11) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
RedirectUri text,
|
||||||
|
State text,
|
||||||
|
Scope varchar(128) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Code)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OAuthAuthData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'State'
|
||||||
|
AND (data_type != 'varchar' OR character_maximum_length != 1024)
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE OAuthAuthData MODIFY State text;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'OAuthAuthData'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_oauthauthdata_client_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_oauthauthdata_client_id ON OAuthAuthData;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS SharedChannelAttachments;
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS SharedChannelAttachments (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
FileId varchar(26) DEFAULT NULL,
|
||||||
|
RemoteId varchar(26) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
LastSyncAt bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
UNIQUE KEY FileId (FileId,RemoteId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
31
db/migrations/mysql/000036_create_sharedchannelusers.down.sql
Обычный файл
31
db/migrations/mysql/000036_create_sharedchannelusers.down.sql
Обычный файл
@@ -0,0 +1,31 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'SharedChannelUsers'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_sharedchannelusers_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_sharedchannelusers_user_id ON SharedChannelUsers(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SharedChannelUsers'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ChannelId'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE SharedChannelUsers DROP COLUMN ChannelId;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS SharedChannelUsers;
|
||||||
68
db/migrations/mysql/000036_create_sharedchannelusers.up.sql
Обычный файл
68
db/migrations/mysql/000036_create_sharedchannelusers.up.sql
Обычный файл
@@ -0,0 +1,68 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS SharedChannelUsers (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
RemoteId varchar(26) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
LastSyncAt bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SharedChannelUsers'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ChannelId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE SharedChannelUsers ADD ChannelId varchar(26) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM information_schema.TABLE_CONSTRAINTS
|
||||||
|
WHERE table_name = 'SharedChannelUsers'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND constraint_type = 'UNIQUE'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE SharedChannelUsers ADD CONSTRAINT UNIQUE KEY UserId(UserId, ChannelId, RemoteId)'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfUniqueNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfUniqueNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfUniqueNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'SharedChannelUsers'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_sharedchannelusers_user_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_sharedchannelusers_user_id ON SharedChannelUsers;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'SharedChannelUsers'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_sharedchannelusers_remote_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_sharedchannelusers_remote_id ON SharedChannelUsers(RemoteId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
31
db/migrations/mysql/000037_create_sharedchannelremotes.down.sql
Обычный файл
31
db/migrations/mysql/000037_create_sharedchannelremotes.down.sql
Обычный файл
@@ -0,0 +1,31 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SharedChannelRemotes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'LastPostId'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE SharedChannelRemotes DROP COLUMN LastPostId;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SharedChannelRemotes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'LastPostUpdateAt'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE SharedChannelRemotes DROP COLUMN LastPostUpdateAt;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS SharedChannelRemotes;
|
||||||
42
db/migrations/mysql/000037_create_sharedchannelremotes.up.sql
Обычный файл
42
db/migrations/mysql/000037_create_sharedchannelremotes.up.sql
Обычный файл
@@ -0,0 +1,42 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS SharedChannelRemotes (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
ChannelId varchar(26) NOT NULL,
|
||||||
|
CreatorId varchar(26) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
IsInviteAccepted tinyint(1) DEFAULT NULL,
|
||||||
|
IsInviteConfirmed tinyint(1) DEFAULT NULL,
|
||||||
|
RemoteId varchar(26) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id, ChannelId),
|
||||||
|
UNIQUE KEY ChannelId (ChannelId, RemoteId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SharedChannelRemotes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'LastPostUpdateAt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE SharedChannelRemotes ADD LastPostUpdateAt bigint;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SharedChannelRemotes'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'LastPostId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE SharedChannelRemotes ADD LastPostId VARCHAR(26);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
1
db/migrations/mysql/000038_create_jobs.down.sql
Обычный файл
1
db/migrations/mysql/000038_create_jobs.down.sql
Обычный файл
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS Jobs;
|
||||||
13
db/migrations/mysql/000038_create_jobs.up.sql
Обычный файл
13
db/migrations/mysql/000038_create_jobs.up.sql
Обычный файл
@@ -0,0 +1,13 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Jobs (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
Type varchar(32) DEFAULT NULL,
|
||||||
|
Priority bigint(20) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
StartAt bigint(20) DEFAULT NULL,
|
||||||
|
LastActivityAt bigint(20) DEFAULT NULL,
|
||||||
|
Status varchar(32) DEFAULT NULL,
|
||||||
|
Progress bigint(20) DEFAULT NULL,
|
||||||
|
Data text,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
KEY idx_jobs_type (Type)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS ChannelMemberHistory;
|
||||||
37
db/migrations/mysql/000039_create_channel_member_history.up.sql
Обычный файл
37
db/migrations/mysql/000039_create_channel_member_history.up.sql
Обычный файл
@@ -0,0 +1,37 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS ChannelMemberHistory (
|
||||||
|
ChannelId varchar(26) NOT NULL,
|
||||||
|
UserId varchar(26) NOT NULL,
|
||||||
|
JoinTime bigint(20) NOT NULL,
|
||||||
|
LeaveTime bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (ChannelId, UserId, JoinTime)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'ChannelMemberHistory'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Email'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE ChannelMemberHistory DROP COLUMN Email',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'ChannelMemberHistory'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Username'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE ChannelMemberHistory DROP COLUMN Username',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
47
db/migrations/mysql/000040_create_sidebar_categories.down.sql
Обычный файл
47
db/migrations/mysql/000040_create_sidebar_categories.down.sql
Обычный файл
@@ -0,0 +1,47 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SidebarCategories'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Collapsed'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE SidebarCategories DROP COLUMN Collapsed;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SidebarCategories'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Muted'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE SidebarCategories DROP COLUMN Muted;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SidebarCategories'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Id'
|
||||||
|
AND column_type != 'varchar(26)'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE SidebarCategories MODIFY Id varchar(26);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS SidebarCategories;
|
||||||
56
db/migrations/mysql/000040_create_sidebar_categories.up.sql
Обычный файл
56
db/migrations/mysql/000040_create_sidebar_categories.up.sql
Обычный файл
@@ -0,0 +1,56 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS SidebarCategories (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
TeamId varchar(26) DEFAULT NULL,
|
||||||
|
SortOrder bigint(20) DEFAULT NULL,
|
||||||
|
Sorting varchar(64) DEFAULT NULL,
|
||||||
|
Type varchar(64) DEFAULT NULL,
|
||||||
|
DisplayName varchar(64) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SidebarCategories'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Id'
|
||||||
|
AND column_type != 'varchar(128)'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE SidebarCategories MODIFY Id varchar(128);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SidebarCategories'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Muted'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE SidebarCategories ADD COLUMN Muted tinyint(1);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'SidebarCategories'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Collapsed'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE SidebarCategories ADD COLUMN Collapsed tinyint(1);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
31
db/migrations/mysql/000041_create_upload_sessions.down.sql
Обычный файл
31
db/migrations/mysql/000041_create_upload_sessions.down.sql
Обычный файл
@@ -0,0 +1,31 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'UploadSessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'RemoteId'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE UploadSessions DROP RemoteId;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'UploadSessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ReqFileId'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE UploadSessions DROP ReqFileId;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS UploadSessions;
|
||||||
87
db/migrations/mysql/000041_create_upload_sessions.up.sql
Обычный файл
87
db/migrations/mysql/000041_create_upload_sessions.up.sql
Обычный файл
@@ -0,0 +1,87 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS UploadSessions (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
Type varchar(32) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UserId varchar(26) DEFAULT NULL,
|
||||||
|
ChannelId varchar(26) DEFAULT NULL,
|
||||||
|
Filename text,
|
||||||
|
Path text,
|
||||||
|
FileSize bigint(20) DEFAULT NULL,
|
||||||
|
FileOffset bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id)
|
||||||
|
);
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'UploadSessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_uploadsessions_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_uploadsessions_user_id ON UploadSessions(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'UploadSessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_uploadsessions_create_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_uploadsessions_create_at ON UploadSessions(CreateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'UploadSessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_uploadsessions_type'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_uploadsessions_type ON UploadSessions(Type);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'UploadSessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'RemoteId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE UploadSessions ADD RemoteId varchar(26) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'UploadSessions'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ReqFileId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE UploadSessions ADD ReqFileId varchar(26) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
31
db/migrations/mysql/000042_create_threads.down.sql
Обычный файл
31
db/migrations/mysql/000042_create_threads.down.sql
Обычный файл
@@ -0,0 +1,31 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Threads'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_threads_channel_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_threads_channel_id ON Threads;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Threads'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ChannelId'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Threads DROP COLUMN ChannelId;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Threads;
|
||||||
42
db/migrations/mysql/000042_create_threads.up.sql
Обычный файл
42
db/migrations/mysql/000042_create_threads.up.sql
Обычный файл
@@ -0,0 +1,42 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Threads (
|
||||||
|
PostId varchar(26) NOT NULL,
|
||||||
|
ReplyCount bigint(20),
|
||||||
|
LastReplyAt bigint(20),
|
||||||
|
Participants text,
|
||||||
|
PRIMARY KEY (PostId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Threads'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ChannelId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Threads ADD COLUMN ChannelId VARCHAR(26) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Threads'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_threads_channel_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_threads_channel_id ON Threads(ChannelId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
UPDATE Threads
|
||||||
|
INNER JOIN Posts ON Posts.Id=Threads.PostId
|
||||||
|
SET Threads.ChannelId=Posts.ChannelId
|
||||||
|
WHERE Threads.ChannelId IS NULL;
|
||||||
62
db/migrations/mysql/000043_thread_memberships.down.sql
Обычный файл
62
db/migrations/mysql/000043_thread_memberships.down.sql
Обычный файл
@@ -0,0 +1,62 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ThreadMemberships'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_thread_memberships_user_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_thread_memberships_user_id ON ThreadMemberships;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ThreadMemberships'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_thread_memberships_last_view_at'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_thread_memberships_last_view_at ON ThreadMemberships;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ThreadMemberships'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_thread_memberships_last_update_at'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_thread_memberships_last_update_at ON ThreadMemberships;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'ThreadMemberships'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'UnreadMentions'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE ThreadMemberships DROP COLUMN UnreadMentions;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS ThreadMemberships;
|
||||||
68
db/migrations/mysql/000043_thread_memberships.up.sql
Обычный файл
68
db/migrations/mysql/000043_thread_memberships.up.sql
Обычный файл
@@ -0,0 +1,68 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS ThreadMemberships (
|
||||||
|
PostId varchar(26) NOT NULL,
|
||||||
|
UserId varchar(26) NOT NULL,
|
||||||
|
Following tinyint(1),
|
||||||
|
LastViewed bigint(20) DEFAULT NULL,
|
||||||
|
LastUpdated bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (PostId, UserId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'ThreadMemberships'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'UnreadMentions'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE ThreadMemberships ADD UnreadMentions bigint(20) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ThreadMemberships'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_thread_memberships_last_update_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_thread_memberships_last_update_at ON ThreadMemberships(LastUpdated);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ThreadMemberships'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_thread_memberships_last_view_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_thread_memberships_last_view_at ON ThreadMemberships(LastViewed);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'ThreadMemberships'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_thread_memberships_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_thread_memberships_user_id ON ThreadMemberships(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
16
db/migrations/mysql/000044_create_user_terms_of_service.down.sql
Обычный файл
16
db/migrations/mysql/000044_create_user_terms_of_service.down.sql
Обычный файл
@@ -0,0 +1,16 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'UserTermsOfService'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_user_terms_of_service_user_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_user_terms_of_service_user_id ON UserTermsOfService(UserId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS UserTermsOfService;
|
||||||
43
db/migrations/mysql/000044_create_user_terms_of_service.up.sql
Обычный файл
43
db/migrations/mysql/000044_create_user_terms_of_service.up.sql
Обычный файл
@@ -0,0 +1,43 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS UserTermsOfService (
|
||||||
|
UserId varchar(26) NOT NULL,
|
||||||
|
TermsOfServiceId varchar(26) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (UserId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
CREATE PROCEDURE MigrateToUserTermsOfServiceTable()
|
||||||
|
BEGIN
|
||||||
|
DECLARE COL_EXIST INT;
|
||||||
|
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'AcceptedTermsOfServiceId' INTO COL_EXIST;
|
||||||
|
|
||||||
|
IF(COL_EXIST > 0) THEN
|
||||||
|
INSERT INTO UserTermsOfService
|
||||||
|
SELECT Id, AcceptedTermsOfServiceId as TermsOfServiceId, ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000)
|
||||||
|
FROM Users
|
||||||
|
WHERE AcceptedTermsOfServiceId != ''
|
||||||
|
AND AcceptedTermsOfServiceId IS NOT NULL;
|
||||||
|
END IF;
|
||||||
|
END;
|
||||||
|
|
||||||
|
CALL MigrateToUserTermsOfServiceTable();
|
||||||
|
|
||||||
|
DROP PROCEDURE IF EXISTS MigrateToUserTermsOfServiceTable;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'UserTermsOfService'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_user_terms_of_service_user_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_user_terms_of_service_user_id ON UserTermsOfService;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT Column_Default FROM Information_Schema.Columns
|
||||||
|
WHERE table_name = 'PluginKeyValueStore'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ExpireAt'
|
||||||
|
) IS NULL,
|
||||||
|
'ALTER TABLE PluginKeyValueStore ALTER COLUMN ExpireAt SET DEFAULT 0;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfDefaultNull FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfDefaultNull;
|
||||||
|
DEALLOCATE PREPARE alterIfDefaultNull;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'PluginKeyValueStore'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ExpireAt'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE PluginKeyValueStore DROP COLUMN ExpireAt;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS PluginKeyValueStore;
|
||||||
36
db/migrations/mysql/000045_create_plugin_key_value_store.up.sql
Обычный файл
36
db/migrations/mysql/000045_create_plugin_key_value_store.up.sql
Обычный файл
@@ -0,0 +1,36 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS PluginKeyValueStore (
|
||||||
|
PluginId varchar(190) NOT NULL,
|
||||||
|
PKey varchar(50) NOT NULL,
|
||||||
|
PValue mediumblob,
|
||||||
|
PRIMARY KEY (PluginId, PKey)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'PluginKeyValueStore'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ExpireAt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE PluginKeyValueStore ADD ExpireAt bigint(20) DEFAULT 0;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT Column_Default FROM Information_Schema.Columns
|
||||||
|
WHERE table_name = 'PluginKeyValueStore'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'ExpireAt'
|
||||||
|
) = 0,
|
||||||
|
'ALTER TABLE PluginKeyValueStore ALTER COLUMN ExpireAt SET DEFAULT NULL;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfDefaultZero FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfDefaultZero;
|
||||||
|
DEALLOCATE PREPARE alterIfDefaultZero;
|
||||||
31
db/migrations/mysql/000046_create_users.down.sql
Обычный файл
31
db/migrations/mysql/000046_create_users.down.sql
Обычный файл
@@ -0,0 +1,31 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_users_email'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_users_email ON Users(Email);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'RemoteId'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Users DROP RemoteId;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Users;
|
||||||
256
db/migrations/mysql/000046_create_users.up.sql
Обычный файл
256
db/migrations/mysql/000046_create_users.up.sql
Обычный файл
@@ -0,0 +1,256 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS Users (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
Username varchar(64) DEFAULT NULL,
|
||||||
|
Password varchar(128) DEFAULT NULL,
|
||||||
|
AuthData varchar(128) DEFAULT NULL,
|
||||||
|
AuthService varchar(32) DEFAULT NULL,
|
||||||
|
Email varchar(128) DEFAULT NULL,
|
||||||
|
EmailVerified tinyint(1),
|
||||||
|
Nickname varchar(64) DEFAULT NULL,
|
||||||
|
FirstName varchar(64) DEFAULT NULL,
|
||||||
|
LastName varchar(64) DEFAULT NULL,
|
||||||
|
Roles varchar(256) DEFAULT NULL,
|
||||||
|
AllowMarketing tinyint(1),
|
||||||
|
Props text,
|
||||||
|
NotifyProps text,
|
||||||
|
LastPasswordUpdate bigint(20) DEFAULT NULL,
|
||||||
|
LastPictureUpdate bigint(20) DEFAULT NULL,
|
||||||
|
FailedAttempts integer,
|
||||||
|
Locale varchar(5) DEFAULT NULL,
|
||||||
|
MfaActive tinyint(1),
|
||||||
|
MfaSecret varchar(128) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
UNIQUE KEY Username (Username),
|
||||||
|
UNIQUE KEY AuthData (AuthData),
|
||||||
|
UNIQUE KEY Email (Email)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'LastActivityAt'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Users DROP COLUMN LastActivityAt;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'LastPingAt'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Users DROP COLUMN LastPingAt;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
UPDATE Users SET Roles = 'system_user' WHERE Roles = '';
|
||||||
|
UPDATE Users SET Roles = 'system_user system_admin' WHERE Roles = 'system_admin';
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Position'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Users ADD Position varchar(128) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Timezone'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Users ADD Timezone varchar(256) DEFAULT \'{"automaticTimezone":"","manualTimezone":"","useAutomaticTimezone":"true"}\';'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Position'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Users MODIFY Position varchar(128);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
UPDATE Users SET AuthData=LOWER(AuthData) WHERE AuthService = 'saml';
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT MIN(CHAR_LENGTH(Roles)) - MAX(CHAR_LENGTH(Roles))
|
||||||
|
FROM Users
|
||||||
|
) != 0,
|
||||||
|
'ALTER TABLE Users MODIFY Roles varchar(256);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE updateIfMissmatch FROM @preparedStatement;
|
||||||
|
EXECUTE updateIfMissmatch;
|
||||||
|
DEALLOCATE PREPARE updateIfMissmatch;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_users_update_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_users_update_at ON Users(UpdateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_users_create_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_users_create_at ON Users(CreateAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_users_delete_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_users_delete_at ON Users(DeleteAt);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_users_all_txt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE FULLTEXT INDEX idx_users_all_txt ON Users(Username, FirstName, LastName, Nickname, Email);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_users_all_no_full_name_txt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE FULLTEXT INDEX idx_users_all_no_full_name_txt ON Users(Username, Nickname, Email);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_users_names_txt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE FULLTEXT INDEX idx_users_names_txt ON Users(Username, FirstName, LastName, Nickname);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_users_names_no_full_name_txt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE FULLTEXT INDEX idx_users_names_no_full_name_txt ON Users(Username, Nickname);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'RemoteId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE Users ADD RemoteId VARCHAR(26);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Users'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_users_email'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_users_email ON Users;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
91
db/migrations/mysql/000047_create_file_info.down.sql
Обычный файл
91
db/migrations/mysql/000047_create_file_info.down.sql
Обычный файл
@@ -0,0 +1,91 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'RemoteId'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE FileInfo DROP COLUMN RemoteId;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_fileinfo_content_txt'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_fileinfo_content_txt ON FileInfo;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Content'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE FileInfo DROP COLUMN Content;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'MiniPreview'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE FileInfo DROP COLUMN MiniPreview;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_fileinfo_name_txt'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_fileinfo_name_txt ON FileInfo;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_fileinfo_extension_at'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_fileinfo_extension_at ON FileInfo;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS FileInfo;
|
||||||
113
db/migrations/mysql/000047_create_file_info.up.sql
Обычный файл
113
db/migrations/mysql/000047_create_file_info.up.sql
Обычный файл
@@ -0,0 +1,113 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS FileInfo (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreatorId varchar(26) DEFAULT NULL,
|
||||||
|
PostId varchar(26) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
DeleteAt bigint(20) DEFAULT NULL,
|
||||||
|
Path text,
|
||||||
|
ThumbnailPath text,
|
||||||
|
PreviewPath text,
|
||||||
|
Name text,
|
||||||
|
Extension varchar(64) DEFAULT NULL,
|
||||||
|
Size bigint(20) DEFAULT NULL,
|
||||||
|
MimeType text,
|
||||||
|
Width int(11) DEFAULT NULL,
|
||||||
|
Height int(11) DEFAULT NULL,
|
||||||
|
HasPreviewImage tinyint(1) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (Id),
|
||||||
|
KEY idx_fileinfo_update_at (UpdateAt),
|
||||||
|
KEY idx_fileinfo_create_at (CreateAt),
|
||||||
|
KEY idx_fileinfo_delete_at (DeleteAt),
|
||||||
|
KEY idx_fileinfo_postid_at (PostId)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_fileinfo_extension_at'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_fileinfo_extension_at ON FileInfo (Extension);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_fileinfo_name_txt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE FULLTEXT INDEX idx_fileinfo_name_txt ON FileInfo (Name);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'MiniPreview'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE FileInfo ADD MiniPreview mediumblob;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Content'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE FileInfo ADD Content longtext;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_fileinfo_content_txt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE FULLTEXT INDEX idx_fileinfo_content_txt ON FileInfo (Content);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'FileInfo'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'RemoteId'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE FileInfo ADD COLUMN RemoteId varchar(26);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterNotIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterNotIfExists;
|
||||||
|
DEALLOCATE PREPARE alterNotIfExists;
|
||||||
46
db/migrations/mysql/000048_create_oauth_apps.down.sql
Обычный файл
46
db/migrations/mysql/000048_create_oauth_apps.down.sql
Обычный файл
@@ -0,0 +1,46 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OAuthApps'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'IconURL'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE OAuthApps DROP COLUMN IconURL;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OAuthApps'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'IsTrusted'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE OAuthApps DROP COLUMN IsTrusted;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'OAuthApps'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_oauthapps_creator_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_oauthapps_creator_id ON OAuthApps;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS OAuthApps;
|
||||||
57
db/migrations/mysql/000048_create_oauth_apps.up.sql
Обычный файл
57
db/migrations/mysql/000048_create_oauth_apps.up.sql
Обычный файл
@@ -0,0 +1,57 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS OAuthApps (
|
||||||
|
Id varchar(26) NOT NULL,
|
||||||
|
CreatorId varchar(26) DEFAULT NULL,
|
||||||
|
CreateAt bigint(20) DEFAULT NULL,
|
||||||
|
UpdateAt bigint(20) DEFAULT NULL,
|
||||||
|
ClientSecret varchar(128) DEFAULT NULL,
|
||||||
|
Name varchar(64) DEFAULT NULL,
|
||||||
|
Description text,
|
||||||
|
CallbackUrls text,
|
||||||
|
Homepage text,
|
||||||
|
PRIMARY KEY (Id)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'OAuthApps'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_oauthapps_creator_id'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_oauthapps_creator_id ON OAuthApps(CreatorId);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OAuthApps'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'IsTrusted'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OAuthApps ADD IsTrusted tinyint(1) DEFAULT NULL;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'OAuthApps'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'IconURL'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'ALTER TABLE OAuthApps ADD IconURL text;'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfNotExists;
|
||||||
|
DEALLOCATE PREPARE alterIfNotExists;
|
||||||
136
db/migrations/mysql/000049_create_channels.down.sql
Обычный файл
136
db/migrations/mysql/000049_create_channels.down.sql
Обычный файл
@@ -0,0 +1,136 @@
|
|||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Channels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_channels_name'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_channels_name ON Channels(Name);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Channels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Shared'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Channels DROP COLUMN Shared;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Channels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_channels_scheme_id'
|
||||||
|
) > 0,
|
||||||
|
'DROP INDEX idx_channels_scheme_id ON Channels;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE removeIndexIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE removeIndexIfExists;
|
||||||
|
DEALLOCATE PREPARE removeIndexIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT column_type FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Channels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'GroupConstrained'
|
||||||
|
) != 'tinyint(4)',
|
||||||
|
'ALTER TABLE Channels MODIFY GroupConstrained tinyint(4);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfTypeDifferent FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfTypeDifferent;
|
||||||
|
DEALLOCATE PREPARE alterIfTypeDifferent;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Channels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'GroupConstrained'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Channels DROP COLUMN GroupConstrained;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Channels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_channels_txt'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_channels_txt ON Channels(Name,DisplayName);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Channels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'SchemeId'
|
||||||
|
) > 0,
|
||||||
|
'ALTER TABLE Channels DROP COLUMN SchemeId;',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfExists FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfExists;
|
||||||
|
DEALLOCATE PREPARE alterIfExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
|
WHERE table_name = 'Channels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND index_name = 'idx_channels_displayname'
|
||||||
|
) > 0,
|
||||||
|
'SELECT 1',
|
||||||
|
'CREATE INDEX idx_channels_displayname ON Channels(DisplayName);'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE createIndexIfNotExists FROM @preparedStatement;
|
||||||
|
EXECUTE createIndexIfNotExists;
|
||||||
|
DEALLOCATE PREPARE createIndexIfNotExists;
|
||||||
|
|
||||||
|
SET @preparedStatement = (SELECT IF(
|
||||||
|
(
|
||||||
|
SELECT column_type FROM INFORMATION_SCHEMA.COLUMNS
|
||||||
|
WHERE table_name = 'Channels'
|
||||||
|
AND table_schema = DATABASE()
|
||||||
|
AND column_name = 'Purpose'
|
||||||
|
) != 'varchar(64)',
|
||||||
|
'ALTER TABLE Channels MODIFY Purpose varchar(64);',
|
||||||
|
'SELECT 1'
|
||||||
|
));
|
||||||
|
|
||||||
|
PREPARE alterIfTypeDifferent FROM @preparedStatement;
|
||||||
|
EXECUTE alterIfTypeDifferent;
|
||||||
|
DEALLOCATE PREPARE alterIfTypeDifferent;
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS Channels;
|
||||||
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Ссылка в новой задаче
Block a user