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

Closed
opened 2025-11-02 04:48:23 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @lsampaioweb on GitHub (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 #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 )

Originally created by @lsampaioweb on GitHub (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 - [x] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [X] 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 #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 )
GiteaMirror added the type/bug label 2025-11-02 04:48:23 -06:00
Author
Owner

@zeripath commented on GitHub (Jan 21, 2019):

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

@zeripath commented on GitHub (Jan 21, 2019): Looks like the mssql variant should have an if exists on its drop index too.
Author
Owner

@zeripath commented on GitHub (Jan 21, 2019):

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.

@zeripath commented on GitHub (Jan 21, 2019): 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.
Author
Owner

@lunny commented on GitHub (Jan 21, 2019):

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

@lunny commented on GitHub (Jan 21, 2019): @lsampaioweb could you change table `version` value from 79 to 78 and restart gitea? That should fix you problem.
Author
Owner

@lsampaioweb commented on GitHub (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 commented on GitHub (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.
Author
Owner

@lsampaioweb commented on GitHub (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

@lsampaioweb commented on GitHub (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
Author
Owner

@lafriks commented on GitHub (Jan 21, 2019):

@lsampaioweb you should be just fine

@lafriks commented on GitHub (Jan 21, 2019): @lsampaioweb you should be just fine
Author
Owner

@w3p706 commented on GitHub (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;

@w3p706 commented on GitHub (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;
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#2785