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

set annotation_id as primary key in annotation_tag table #12970

Closed

Conversation

swtch1
Copy link
Contributor

@swtch1 swtch1 commented Aug 17, 2018

This corrects a failure to migrate/create the annotation_tag table on MariaDB with innodb_force_primary_key=1 which is required for Galera clustering.

setting annotation_id as primary key in table to satisfy innodb_force_primary_key=1

Related to #12971

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Joshua Thornton seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@swtch1
Copy link
Contributor Author

swtch1 commented Aug 17, 2018

Seeing I'm getting a failure in test:

  • /go/src/github.com/grafana/grafana/pkg/services/sqlstore/annotation_test.go
    Line 64:
    Expected: nil
    Actual: 'UNIQUE constraint failed: annotation_tag.annotation_id'

And in Postgres integration:

  • /go/src/github.com/grafana/grafana/pkg/services/sqlstore/annotation_test.go
    Line 64:
    Expected: nil
    Actual: 'pq: duplicate key value violates unique constraint "annotation_tag_pkey"'

Not being familiar with all the uses of the database here I'm not exactly sure where concentrate next. Could I get some direction?

@marefr
Copy link
Member

marefr commented Aug 17, 2018

annotation_id and tag_id probably needs to be primary key. Not sure if that's supported by Grafana migrator. Not sure this change will be allowed for existing annotation_tag tables which could be the next potential problem.

@torkelo
Copy link
Member

torkelo commented Aug 17, 2018

Yea, this won’t work, need a new column if a primary key is needed

@swtch1
Copy link
Contributor Author

swtch1 commented Aug 17, 2018

If I setup an ID field with autoincrement is that they way to go?

@torkelo
Copy link
Member

torkelo commented Aug 20, 2018

yes

@marefr
Copy link
Member

marefr commented Aug 20, 2018

We still need a migration path for that change though I suppose. Basically rename table, create new table, migrate data and drop old table - think that's how we usually do it and it should be examples of that among our migration code.

@bergquist
Copy link
Contributor

bergquist commented Sep 12, 2018

Creating a new table and migrating data won't help if still try to create the table without PK first.

In this case, I think we need to both modify the current migration (won't run if it's already present) and create rename/copy data into a new table with PK to get full consistency.

here is an example of how to create create a new table and migrate the old data https://github.com/grafana/grafana/blob/master/pkg/services/sqlstore/migrations/dashboard_mig.go#L208

@torkelo
Copy link
Member

torkelo commented Dec 19, 2018

Closing this as it needs new id column

@torkelo torkelo closed this Dec 19, 2018
@thestevenbell
Copy link

I'm facing this same issue while using MariaDB, fresh install using docker. Grafana v6.0.1 and 6.0.2. Is there are work around?

msg="Connecting to DB" logger=sqlstore dbtype=mysql
msg="Starting DB migration" logger=migrator
msg="Executing migration" logger=migrator id="Create 
msg="Executing migration failed" logger=migrator error="Error 1173: This table type requires a primary 
msg="Exec failed" logger=migrator error="Error 1173: ey" sql="CREATE TABLE IF NOT EXISTS `annotation_tag` LL\n, `tag_id` BIGINT(20) NOT NULL\n) ENGINE=InnoDB mb4_unicode_ci;"
msg="Server shutdown" logger=server reason="Service rror 1173: This table type requires a primary key"

@bergquist bergquist reopened this Apr 3, 2019
@bergquist bergquist closed this Apr 3, 2019
@ying-jeanne ying-jeanne added the pr/external This PR is from external contributor label Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/external This PR is from external contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants