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

(slightly) more readable migration filenames? #358

Closed
davidszotten opened this Issue Jun 17, 2016 · 6 comments

Comments

Projects
None yet
4 participants
@davidszotten
Contributor

davidszotten commented Jun 17, 2016

What would you think about inserting an underscore between the date and time in the generated migration filenames?

for the odd occasion when typing (tab completing) in a terminal, i found it hard to scan the list of migrations to figure out which number to add to disambiguate and continue tab completing:

$ rm migrations/2016061<TAB>
20160612132127_add_foo/      20160614173422_add_bar/       20160615123204_add_baz/
20160614153823_add_quu/      20160615122959_add_quux/

vs something like?

20160612_132127_add_foo/      20160614_173422_add_bar/       20160615_123204_add_baz/
20160614_153823_add_quu/      20160615_122959_add_quux/
@killercup

This comment has been minimized.

Member

killercup commented Jun 17, 2016

I'm pretty sure you can write it like 20160612-132127_add_foo or even 2016-06-12T13-21-27_add_foo. The 'version' is determined by the filename part before the first _.


Browsing through the migration code, it looks like for all entries in the migrations/ directory, migration_from(path) is called, which tries to build a tuple struct with (path, version), where the 'version' is determined by version_from(path). This is where it gets interesting: It just splits the string at the first _ and returns the first part:

.split("_")
.nth(0)
@davidszotten

This comment has been minimized.

Contributor

davidszotten commented Jun 17, 2016

the dates are prepended by the cli when calling e.g. diesel migration generate foo.

indeed, as you've discovered, internally diesel seems to only use the first part:

table __diesel_schema_migrations
+----------------+----------------------------+
|        version | run_on                     |
|----------------+----------------------------|
| 20160612132127 | 2016-06-15 11:38:36.130818 |
| 20160614153823 | 2016-06-15 11:38:36.130818 |
| 20160614173422 | 2016-06-15 11:38:36.130818 |
| 20160615122959 | 2016-06-15 11:38:36.130818 |
| 20160615123204 | 2016-06-15 11:38:36.130818 |
+----------------+----------------------------+
SELECT 5
Time: 0.002s

hence this issue

@killercup

This comment has been minimized.

Member

killercup commented Jun 17, 2016

Ah, got it. So you basically want to change the generate output, not the underlying migration organisation stuff.

@davidszotten

This comment has been minimized.

Contributor

davidszotten commented Jun 17, 2016

yes, though having the identifiers in the migrations table also separated with an underscore might also be helpful i guess

@sgrif

This comment has been minimized.

Member

sgrif commented Jun 23, 2016

I'm fine with improving the readability of these. I like @killercup's suggestion of using dashes instead of underscores. I'd like to continue to keep the rules of "what is the version" simple (and right now that rule is anything before the first underscore)

@Eijebong

This comment has been minimized.

Member

Eijebong commented Aug 14, 2017

This can be closed now that #827 has been merged :)

@Eijebong Eijebong closed this Aug 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment