New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MM-33077] Add migrations for OAuthApps schema #17209
Changes from 4 commits
19ccc86
4ea0b90
ef3b5b1
0a08320
a04fa3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 0;' | ||
)); | ||
|
||
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 varchar(512) DEFAULT "";' | ||
)); | ||
|
||
PREPARE alterIfNotExists FROM @preparedStatement; | ||
EXECUTE alterIfNotExists; | ||
DEALLOCATE PREPARE alterIfNotExists; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ALTER TABLE oauthapps DROP COLUMN IF EXISTS iconurl; | ||
ALTER TABLE oauthapps DROP COLUMN IF EXISTS istrusted; | ||
|
||
DROP INDEX IF EXISTS idx_oauthapps_creator_id ON oauthapps; | ||
|
||
DROP TABLE IF EXISTS oauthapps; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
CREATE TABLE IF NOT EXISTS oauthapps ( | ||
id VARCHAR(26) PRIMARY KEY, | ||
creatorid VARCHAR(26), | ||
createat bigint, | ||
updateat bigint, | ||
clientsecret VARCHAR(128), | ||
name VARCHAR(64), | ||
description VARCHAR(512), | ||
callbackurls VARCHAR(1024), | ||
homepage VARCHAR(256) | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS idx_oauthapps_creator_id ON oauthapps (creatorid); | ||
|
||
ALTER TABLE oauthapps ADD COLUMN IF NOT EXISTS istrusted boolean DEFAULT false; | ||
ALTER TABLE oauthapps ADD COLUMN IF NOT EXISTS iconurl VARCHAR(512) DEFAULT ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the current system we don't set defaults on creation and usually we prefer to avoid them. I am wondering if we should change these as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, makes sense 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,12 +53,6 @@ func newSqlOAuthStore(sqlStore *SqlStore) store.OAuthStore { | |
return as | ||
} | ||
|
||
func (as SqlOAuthStore) createIndexesIfNotExists() { | ||
as.CreateIndexIfNotExists("idx_oauthapps_creator_id", "OAuthApps", "CreatorId") | ||
as.CreateIndexIfNotExists("idx_oauthaccessdata_user_id", "OAuthAccessData", "UserId") | ||
as.CreateIndexIfNotExists("idx_oauthaccessdata_refresh_token", "OAuthAccessData", "RefreshToken") | ||
Comment on lines
-58
to
-59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are removing stuff for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are forgotten
|
||
} | ||
|
||
func (as SqlOAuthStore) SaveApp(app *model.OAuthApp) (*model.OAuthApp, error) { | ||
if app.Id != "" { | ||
return nil, store.NewErrInvalidInput("OAuthApp", "Id", app.Id) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,7 +260,6 @@ func New(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlS | |
store.stores.channel.(*SqlChannelStore).createIndexesIfNotExists() | ||
store.stores.retentionPolicy.(*SqlRetentionPolicyStore).createIndexesIfNotExists() | ||
store.stores.user.(*SqlUserStore).createIndexesIfNotExists() | ||
store.stores.oauth.(*SqlOAuthStore).createIndexesIfNotExists() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also affects other tables that are not covered in here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related with above. |
||
store.stores.system.(*SqlSystemStore).createIndexesIfNotExists() | ||
store.stores.emoji.(*SqlEmojiStore).createIndexesIfNotExists() | ||
store.stores.fileInfo.(*SqlFileInfoStore).createIndexesIfNotExists() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another general question: I am wondering if it would be simpler for the table creation code to have the most recent version of the table. I am thinking it would be the same logic wise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But in that case we would lose the history right? And if we are going to include the down scripts with the reverse steps it wouldn't be consistent. cc @mgdelacroix