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

Migrate 78 fail on MSSQL if bare index already dropped #5789

Closed
2 of 7 tasks
lsampaioweb opened this issue Jan 21, 2019 · 7 comments
Closed
2 of 7 tasks

Migrate 78 fail on MSSQL if bare index already dropped #5789

lsampaioweb opened this issue Jan 21, 2019 · 7 comments
Labels

Comments

@lsampaioweb
Copy link

lsampaioweb commented Jan 21, 2019

  • Gitea version (or commit ref): f631702 built with: bindata, sqlite, sqlite_unlock_notify
  • Git version: 2.18.1
  • Operating system: Mac OSX Mojave with docker 2.0.0.2 (30215)
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:
    2019/01/20 22:33:17 [I] Migration: rename repo is_bare to repo is_empty
    2019/01/20 22:33:17 [...itea/routers/init.go:81 GlobalInit()] [E] ORM engine initialization failed: migrate: do migrate: Drop index failed: mssql: Cannot drop the index 'repository.IDX_repository_is_bare', because it does not exist or you do not have permission.
    2019/01/20 22:33:17 [I] Beginning ORM engine initialization.
    2019/01/20 22:33:17 [I] ORM engine initialization attempt Rename import paths: "github.com/gogits/gogs" -> "github.com/go-gitea/gitea" #1/10...

Description

Everything is working fine with the docker image gitea/gitea:1.7 (8006b1b), but when I try to run gitea/gitea:latest (f631702) I get a migration error (error message above).
I checked the table "repository" and the index "IDX_repository_is_bare" does not exist nor does the column "is_empty".

I know is something related with the issue ( #5759 )

@zeripath
Copy link
Contributor

Looks like the mssql variant should have an if exists on its drop index too.

@zeripath zeripath changed the title Migrate fail when trying to update to the "latest" version Migrate 78 fail on MSSQL if bare index already dropped Jan 21, 2019
@zeripath
Copy link
Contributor

As a quick workaround if you have access to the db you should be able to recreate the index (I think this is the correct syntax):

CREATE INDEX IDX_repository_is_bare ON repository (is_bare)

Tell me did you try to migrate earlier and fail or is this the first time you've tried to migrate?

If you fancy fixing this and putting in a pr the command is in models/migration/v78.go

The MSSQL drop index variant needs an if exists.

@lunny
Copy link
Member

lunny commented Jan 21, 2019

@lsampaioweb could you change table version value from 79 to 78 and restart gitea? That should fix you problem.

@lsampaioweb
Copy link
Author

lsampaioweb commented Jan 21, 2019

The error message changed to:

Running gitea migrate I get this:
2019/01/21 18:29:18 [...itea/routers/init.go:81 GlobalInit()] [E] ORM engine initialization failed: migrate: do migrate: Drop column failed: mssql: ALTER TABLE DROP COLUMN is_bare failed because one or more objects access this column.

Running the SQL directly on the db I get this:
ALTER TABLE [dbo].[repository] DROP COLUMN [is_bare]

The object 'DF__repositor__is_ba__4F7CD00D' is dependent on column 'is_bare'.
[FreeTDS][MSSQL Server] , Server cc8750d44511, Line 1
ALTER TABLE DROP COLUMN is_bare failed because one or more objects access this column.

@lsampaioweb
Copy link
Author

lsampaioweb commented Jan 21, 2019

I executed the SQL below and now everything is working fine!! Do you guys foresee any side effects?

BEGIN TRANSACTION;
EXEC sp_rename '[dbo].[repository].[is_bare]', 'is_empty', 'COLUMN';
COMMIT TRANSACTION;

2019/01/21 18:48:45 [I] Beginning ORM engine initialization.
2019/01/21 18:48:45 [I] ORM engine initialization attempt #1/10...
2019/01/21 18:48:45 [I] Migration: rename repo is_bare to repo is_empty
2019/01/21 18:48:46 [I] ORM engine initialization successful!
2019/01/21 18:48:46 [I] Git Version: 2.18.1
2019/01/21 18:48:46 [I] SQLite3 Supported
2019/01/21 18:48:46 [I] Run Mode: Production
2019/01/21 18:48:47 [I] Listen: http://0.0.0.0:3000

@lafriks
Copy link
Member

lafriks commented Jan 21, 2019

@lsampaioweb you should be just fine

@w3p706
Copy link

w3p706 commented Apr 9, 2019

I also had the second issue

Drop column failed: mssql: ALTER TABLE DROP COLUMN is_bare failed because one or more objects access this column.

while updating from 1.7.4 to 1.8.0rc2.

This also solved my issue:

BEGIN TRANSACTION;
EXEC sp_rename '[dbo].[repository].[is_bare]', 'is_empty', 'COLUMN';
COMMIT TRANSACTION;

@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
Projects
None yet
Development

No branches or pull requests

6 participants