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

sequences #2

Open
eriktelepovsky opened this issue Feb 1, 2018 · 7 comments
Open

sequences #2

eriktelepovsky opened this issue Feb 1, 2018 · 7 comments

Comments

@eriktelepovsky
Copy link

Hi. Does it also rename sequences?

@alexei
Copy link
Owner

alexei commented Feb 1, 2018

I'm not sure I understand. Could you please provide more info?

@eriktelepovsky
Copy link
Author

eriktelepovsky commented Feb 1, 2018

Let's say I have a model old_app.ModelA. Its primary key id points to sequence old_app_modela_id_seq.

localhost=# \d old_app_modela;
                                      Table "public.old_app_modela"
     Column      |           Type           |                             Modifiers                             
-----------------+--------------------------+-------------------------------------------------------------------
 id              | integer                  | not null default nextval('old_app_modela_id_seq'::regclass)

I decide to move it to new_app. So the next value of primary key should still refer to same sequence, but it should be renamed to new_app_modela_id_seq, like this:

localhost=# \d new_app_modela;
                                      Table "public.new_app_modela"
     Column      |           Type           |                             Modifiers                             
-----------------+--------------------------+-------------------------------------------------------------------
 id              | integer                  | not null default nextval('new_app_modela_id_seq'::regclass)

Basically, it should be done with statement:

ALTER SEQUENCE old_app_modela_id_seq RENAME TO new_app_modela_id_seq;

@alexei
Copy link
Owner

alexei commented Feb 1, 2018

I see. No, it doesn't. Should it?

@eriktelepovsky
Copy link
Author

I think yes, it is convenient and more human readable.

Check this out, it may help you: http://marcela-campo.blogspot.sk/2015/01/django-migrations-moving-django-model.html

@alexei
Copy link
Owner

alexei commented Feb 1, 2018

Thanks for the link. I read that article before implementing this. It doesn't account for other DB engines. For example, SQLite stores sequence information inside a sqlite_sequence table and ALTER SEQUENCE will raise a syntax error. There's also MySQL, Oracle, SQL Server, DB2, Firebird etc.

TBH, the scope of this project is to automate the method described at https://stackoverflow.com/a/30613732/1639699 and, while I understand and agree to the reasoning, renaming sequences seems beyond that.

@alexei
Copy link
Owner

alexei commented Feb 1, 2018

Ideally renaming a sequence would be implemented as a db operation. Those, however, are not documented and currently I'm not sure how to do that.

@alexei
Copy link
Owner

alexei commented Feb 1, 2018

One way to implement an operation would be to simply inherit either RunPython or RunSQL and run the appropriate query (or do nothing?) depending on the engine.

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

No branches or pull requests

2 participants