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
Versioned migrations do not work with GlobalUniqueID #2587
Comments
Some context: Ent currently supports global unique integer ids by allocating specific integer ranges for each node. When using the online migration feature, Ent inspects the connected database, plans the migration changes accordingly and applies them. While this ensures, that later added nodes get a free pk range, it renders it impossible to plan migration files in advance, since the allocated pk ranges depend on the state of the schema when migrating. This could potentially create schema drifts between different environments. In order to support global unique id for versioned migration files as well, the pk range information have to be moved from the database instance to the schema. I propose the following solution:
The online migration and versioned migration engines will both provide an implementation for the following interface: // typeStore wraps methods for loading and storing pk range information for types.
type typeStore interface {
load(context.Context) ([]string, error)
store(context.Context, []string) error
} |
I would probably think of it as how protobuf is being used, where one needs to define the values, and when editing or deleting one, we can then reserve it so as to not shift the existing values. You can also say that you don't want to make something so manual, in which case we can have it be autogenerated once, and then used the rest of the times like you suggested, in which case we'll need to have the autogenerated file committed so that subsequent uses will depend on it when generating the migrations, but I would prefer it to be separated from the autogenerated schema itself since I do not wish to have to commit it. |
I also have an idea about moving Universel ID logic to remote service, and I purpose an interface like this: type EntTypesStore interface {
AllocRange(ctx context.Context, name string) (int, error)
TypeRange(ctx context.Context, name string) (int, bool)
} If we going to this way, I should be awesome. |
The information has to be stored somewhere. With the interface @giautm proposed (with mine as well) it is relatively easy to change the location from a file in the migration directory (schema directory) to something else like a remote service, a database or in the schema itself. What we need to decide is what storage location to support for the offline migrations. @bionic-ido As I understood you prefer something schema config related? |
@masseelch The way we are currently using ent is having the schema definition files be commited into our git, while having a generation script that handles the generation of all the autogenerated files out of it. |
Suppose trying to generate versioned migrations files for a global unique id enabled schema:
will result into the following error:
Current Behavior 😯
There is an error.
Expected Behavior 🤔
A new set of migration files are created that also allocate the correct ranges for the primary keys.
The text was updated successfully, but these errors were encountered: