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

add a timestamp token that can be part of the file_template #622

Closed
taebow opened this issue Nov 12, 2019 · 4 comments
Closed

add a timestamp token that can be part of the file_template #622

taebow opened this issue Nov 12, 2019 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@taebow
Copy link

taebow commented Nov 12, 2019

Wouldn't it be nice to have the migration files (the ones which are in the migration/versions folder) sorted by creation date. These are hard to retrieve without the help of the command alembic history.

I propose a new variable to use in the file_template option, that could be placed at first, so that the file order could be maintained.

Is that reasonable and isn't that somehow a shallow request ?

@zzzeek zzzeek added feature use case not quite a feature and not quite a bug, something we just didn't think of motivated volunteers requested a feature that has noone to implement; can reopen a 'wontfix' and removed use case not quite a feature and not quite a bug, something we just didn't think of labels Nov 12, 2019
@zzzeek zzzeek changed the title Migration files sorted by creation time add a timestamp token that can be part of the file_template Nov 12, 2019
@zzzeek
Copy link
Member

zzzeek commented Nov 12, 2019

Sure can you:

a. propose the format of this date stamp

b. provide a pull request with tests

@taebow
Copy link
Author

taebow commented Nov 18, 2019

My idea at first, was to provide an incremental value so that we could have migration files organized as follow :

migrations/
  version/
    0_initial_migration.py
    1_alter_column_x_on_table_y.py
    2_change_type_of_column_z_on_table_w.py

As previously mentioned, it is perhaps a shallow feature to implement, comparing what has to be done in terms of development (thinking about getting the value from history or directly from fs) and the usefulness of the feature.

The other interpretation, that was raised in your answer, was to provide a timestamp value, and so I see 2 kinds of values:
- A true timestamp, which should be the result of int(datetime.timestamp(create_date).
- A datetime value in the form of datetime.strftime(create_date, "%Y%m%d%H%M%S") but could be easily obtain without new development with the existing datetime based variables.

To conclude, I have no idea which one is preferable.

@zzzeek
Copy link
Member

zzzeek commented Nov 18, 2019

the incremental value is a non-starter. this is one of the disastrous decisions made by the SQLAlchemy-migrate project that Alembic sought to correct for. Database migrations are not necessarily linear and there is always a need to add new migrations between existing ones when dealing with situations like branch merges.

As for the date tokens, we actually already have these and this issue is a duplicate of #59 .

it's documented in the tutorial:

- file_template - this is the naming scheme used to generate new migration files. The value present is the default, so is commented out. Tokens available include:

        %%(rev)s - revision id

        %%(slug)s - a truncated string derived from the revision message

        %%(year)d, %%(month).2d, %%(day).2d, %%(hour).2d, %%(minute).2d, %%(second).2d - components of the create date, by default datetime.datetime.now() unless the timezone configuration option is also used.

- timezone - an optional timezone name (e.g. UTC, EST5EDT, etc.) that will be applied to the timestamp which renders inside the migration file’s comment as well as within the filename. If timezone is specified, the create date object is no longer derived from datetime.datetime.now() and is instead generated as:

datetime.datetime.utcnow().replace(
      tzinfo=dateutil.tz.tzutc()
).astimezone(
    dateutil.tz.gettz(<timezone>)
)



@zzzeek zzzeek added duplicate This issue or pull request already exists and removed feature motivated volunteers requested a feature that has noone to implement; can reopen a 'wontfix' labels Nov 18, 2019
@zzzeek
Copy link
Member

zzzeek commented Nov 18, 2019

this behavior is already documented, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants