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

indexer: DB reset to handle incomplete migration history #19019

Merged
merged 1 commit into from
Aug 16, 2024

Conversation

gegaowp
Copy link
Contributor

@gegaowp gegaowp commented Aug 16, 2024

Description

previous fix did not work well when migration run history in __diesel_schema_migrations table is not complete.

I also considered dropping the database as we usually do locally, but a connection cannot drop the database in its own connection and ended up having errors of

cannot drop the currently open database

thus this pr drops all tables, functions and procedures explicitly for PG and tables for MySQL as we now only have tables in MySQL.

Test plan

  1. diesel reset on latest main
  2. cherry-pick this pr to 1.31 and 1.30, run cmd below and make sure that DB are indeed reset
DB_POOL_SIZE=10 cargo run --bin sui-indexer -- --db-url =DB_URL --reset-db

Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • REST API:

Copy link

vercel bot commented Aug 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 16, 2024 5:33pm

Copy link

vercel bot commented Aug 16, 2024

@gegaowp is attempting to deploy a commit to the Mysten Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@amnn amnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of this approach -- it seems to be baking in implementation details from diesel into our own code.

Am I right in thinking that this is just for the purposes of CI? If so, can we use diesel's own diesel migration etc to achieve the same effect?

@gegaowp
Copy link
Contributor Author

gegaowp commented Aug 16, 2024

@amn

Am I right in thinking that this is just for the purposes of CI? If so, can we use diesel's own diesel migration etc to achieve the same effect?

not only for CI but for all DB reset env like staging and devnet too. Counting on migrations file is fragile while we are making changes in a breaking / non-incremental way, for example if we change a table name from table_a to table_b, then next time if we do db-reset by reverting all migrations, table_a will not be dropped as DROP TABLE IF EXISTS table_a has been modified.

this is even worse when we have inconsistency between migration history in __diesel_schema_migrations and schema itself, which is what I saw today in CI and that caused failures. Not sure where the inconsistency was introduced but here a total reset instead of reverting all migrations is necessary afaict.

@amnn
Copy link
Contributor

amnn commented Aug 16, 2024

Is this not another example of what happens if you work against the intended usage of diesel's migration feature? I.e. if we did not modify migrations after we checked them in and only added new migrations in response to changes, could we then use the diesel CLI for this?

IIUC we want to eventually have a clean starting point for the schema once it is settled, and that is why we are going back and modifying migration files, but can we get the best of both worlds by using migrations as intended until we are happy with the schema, then squashing everything down into the final schema files as a single breaking change?

@gegaowp
Copy link
Contributor Author

gegaowp commented Aug 16, 2024

what happens if you work against the intended usage of diesel's migration feature? can we get the best of both worlds by using migrations as intended until we are happy with the schema, then squashing everything down into the final schema files as a single breaking change?

this is a fair point, but now the DB reset is solved by this pr, so we can squash the changes on each migration changes and that leaves the schema always compact and intuitive. I am open to this why-not-both idea tho if more relevant issues pop up and requires more baking.

@gegaowp gegaowp merged commit 8574a5b into MystenLabs:main Aug 16, 2024
41 of 44 checks passed
@gegaowp gegaowp deleted the db-reset-fix-again branch August 16, 2024 17:52
gegaowp added a commit to gegaowp/sui that referenced this pull request Aug 16, 2024
…19019)

## Description 

previous fix did not work well when migration run history in
__diesel_schema_migrations table is not complete.

I also considered dropping the database as we usually do locally, but a
connection cannot drop the database in its own connection and ended up
having errors of
```
cannot drop the currently open database
```

thus this pr drops all tables, functions and procedures explicitly for
PG and tables for MySQL as we now only have tables in MySQL.

## Test plan 

1. diesel reset on latest main
2. cherry-pick this pr to 1.31 and 1.30, run cmd below and make sure
that DB are indeed reset
```
DB_POOL_SIZE=10 cargo run --bin sui-indexer -- --db-url =DB_URL --reset-db
```

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
gegaowp added a commit to gegaowp/sui that referenced this pull request Aug 16, 2024
…19019)

## Description 

previous fix did not work well when migration run history in
__diesel_schema_migrations table is not complete.

I also considered dropping the database as we usually do locally, but a
connection cannot drop the database in its own connection and ended up
having errors of
```
cannot drop the currently open database
```

thus this pr drops all tables, functions and procedures explicitly for
PG and tables for MySQL as we now only have tables in MySQL.

## Test plan 

1. diesel reset on latest main
2. cherry-pick this pr to 1.31 and 1.30, run cmd below and make sure
that DB are indeed reset
```
DB_POOL_SIZE=10 cargo run --bin sui-indexer -- --db-url =DB_URL --reset-db
```

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
@amnn
Copy link
Contributor

amnn commented Aug 16, 2024

Yes, this is okay for us to unblock this release, but is not a long-term solution. We are only making things more brittle by relying on diesel's implementation details. I have added this as one of the topics for design discussions (although we have quite a few of these to get through, so maybe not for the coming Monday).

gegaowp added a commit to gegaowp/sui that referenced this pull request Aug 16, 2024
…19019)

## Description 

previous fix did not work well when migration run history in
__diesel_schema_migrations table is not complete.

I also considered dropping the database as we usually do locally, but a
connection cannot drop the database in its own connection and ended up
having errors of
```
cannot drop the currently open database
```

thus this pr drops all tables, functions and procedures explicitly for
PG and tables for MySQL as we now only have tables in MySQL.

## Test plan 

1. diesel reset on latest main
2. cherry-pick this pr to 1.31 and 1.30, run cmd below and make sure
that DB are indeed reset
```
DB_POOL_SIZE=10 cargo run --bin sui-indexer -- --db-url =DB_URL --reset-db
```

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
gegaowp added a commit to gegaowp/sui that referenced this pull request Aug 16, 2024
…19019)

## Description 

previous fix did not work well when migration run history in
__diesel_schema_migrations table is not complete.

I also considered dropping the database as we usually do locally, but a
connection cannot drop the database in its own connection and ended up
having errors of
```
cannot drop the currently open database
```

thus this pr drops all tables, functions and procedures explicitly for
PG and tables for MySQL as we now only have tables in MySQL.

## Test plan 

1. diesel reset on latest main
2. cherry-pick this pr to 1.31 and 1.30, run cmd below and make sure
that DB are indeed reset
```
DB_POOL_SIZE=10 cargo run --bin sui-indexer -- --db-url =DB_URL --reset-db
```

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
gegaowp added a commit that referenced this pull request Aug 16, 2024
## Description 

#19019

## Test plan 

#19019

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
ebmifa pushed a commit that referenced this pull request Aug 16, 2024
## Description 

previous fix did not work well when migration run history in
__diesel_schema_migrations table is not complete.

I also considered dropping the database as we usually do locally, but a
connection cannot drop the database in its own connection and ended up
having errors of
```
cannot drop the currently open database
```

thus this pr drops all tables, functions and procedures explicitly for
PG and tables for MySQL as we now only have tables in MySQL.

## Test plan 

1. diesel reset on latest main
2. cherry-pick this pr to 1.31 and 1.30, run cmd below and make sure
that DB are indeed reset
```
DB_POOL_SIZE=10 cargo run --bin sui-indexer -- --db-url =DB_URL --reset-db
```

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
tx-tomcat pushed a commit to tx-tomcat/sui-network that referenced this pull request Aug 27, 2024
…19019)

## Description 

previous fix did not work well when migration run history in
__diesel_schema_migrations table is not complete.

I also considered dropping the database as we usually do locally, but a
connection cannot drop the database in its own connection and ended up
having errors of
```
cannot drop the currently open database
```

thus this pr drops all tables, functions and procedures explicitly for
PG and tables for MySQL as we now only have tables in MySQL.

## Test plan 

1. diesel reset on latest main
2. cherry-pick this pr to 1.31 and 1.30, run cmd below and make sure
that DB are indeed reset
```
DB_POOL_SIZE=10 cargo run --bin sui-indexer -- --db-url =DB_URL --reset-db
```

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
suiwombat pushed a commit that referenced this pull request Sep 16, 2024
## Description 

previous fix did not work well when migration run history in
__diesel_schema_migrations table is not complete.

I also considered dropping the database as we usually do locally, but a
connection cannot drop the database in its own connection and ended up
having errors of
```
cannot drop the currently open database
```

thus this pr drops all tables, functions and procedures explicitly for
PG and tables for MySQL as we now only have tables in MySQL.

## Test plan 

1. diesel reset on latest main
2. cherry-pick this pr to 1.31 and 1.30, run cmd below and make sure
that DB are indeed reset
```
DB_POOL_SIZE=10 cargo run --bin sui-indexer -- --db-url =DB_URL --reset-db
```

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants