Skip to content
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

Fix Migration 145 on MSSQL if varchar is changed to nvarchar #12445

Merged
merged 9 commits into from
Aug 10, 2020

Conversation

zeripath
Copy link
Contributor

@zeripath zeripath commented Aug 6, 2020

Some versions of MSSQL will fail on migration v145 because there is a constraint failure.

This PR drops the constraints on the language column prior to its alteration and then recreates them with sync.

Fix #12441
Fix #13013

Signed-off-by: Andrew Thornton art27@cantab.net

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath zeripath added this to the 1.13.0 milestone Aug 6, 2020
models/migrations/v145.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 6, 2020
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Aug 6, 2020
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Aug 8, 2020
@zeripath
Copy link
Contributor Author

zeripath commented Aug 9, 2020

Make lg-tm work

models/migrations/v145.go Outdated Show resolved Hide resolved
models/migrations/v145.go Outdated Show resolved Hide resolved
@lafriks
Copy link
Member

lafriks commented Aug 9, 2020

Still fails with error:

mssql: The operation failed because an index or statistics with name 'UQE_language_stat_s' already exists on table 'language_stat'.

@zeripath
Copy link
Contributor Author

zeripath commented Aug 10, 2020

It looks like:

SELECT Name FROM SYS.DEFAULT_CONSTRAINTS WHERE 
	PARENT_OBJECT_ID = OBJECT_ID('language_stat') AND
	PARENT_COLUMN_ID IN (SELECT column_id FROM sys.columns
		WHERE lower(NAME) = 'language' AND object_id = OBJECT_ID('language_stat')

isn't finding the unique constraint. Which is weird

Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

OK I'm going to try a different query...

SELECT i.name AS Name
	FROM sys.indexes i INNER JOIN sys.index_columns ic
		ON i.index_id = ic.index_id AND i.object_id = ic.object_id
	INNER JOIN sys.tables AS t 
		ON t.object_id = i.object_id
	INNER JOIN sys.columns c
		ON t.object_id = c.object_id AND ic.column_id = c.column_id
	WHERE t.name = 'language_stat' AND c.name = 'language'

Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
@zeripath
Copy link
Contributor Author

OK that finally appears to work.

@lafriks lafriks merged commit d87dbd7 into go-gitea:master Aug 10, 2020
@zeripath zeripath deleted the re-fix-145 branch August 10, 2020 17:55
@zeripath zeripath added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Aug 13, 2020
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. type/bug
Projects
None yet
4 participants