Skip to content

Commit

Permalink
fix: migration generator indexes (#625)
Browse files Browse the repository at this point in the history
* Fix generator so it does not create a single index over id, created_at, updated_at but separate indexes.

* Generate separate indices
Don't generate index for id (covered by PRIMARY already)

* Update example & test app migrations with correct indexes
  • Loading branch information
nickschot authored and zacharygolba committed Jan 16, 2017
1 parent 93aa5c4 commit ebbcf57
Show file tree
Hide file tree
Showing 22 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export function up(schema) {
.notNullable();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export function up(schema) {
.notNullable();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export function up(schema) {
.notNullable();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
6 changes: 2 additions & 4 deletions examples/todo/db/migrate/2016051617272695-create-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ export function up(schema) {
table.integer('list_id').index();

table.timestamps();
table.index([
'created_at',
'updated_at'
]);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
6 changes: 2 additions & 4 deletions examples/todo/db/migrate/2016051617273905-create-lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ export function up(schema) {
.notNullable();

table.timestamps();
table.index([
'created_at',
'updated_at'
]);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
7 changes: 2 additions & 5 deletions src/packages/cli/templates/model-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ export default (name: string, attrs: Array<string> | string): string => {
${body}
table.timestamps();
table.index([
'id',
'created_at',
'updated_at'
]);
table.index('created_at');
table.index('updated_at');
});
}
Expand Down
3 changes: 2 additions & 1 deletion test/test-app/db/migrate/2016051621371582-create-users.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export function up(schema) {
.notNullable();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
3 changes: 2 additions & 1 deletion test/test-app/db/migrate/2016051621393305-create-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export function up(schema) {
.notNullable();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
3 changes: 2 additions & 1 deletion test/test-app/db/migrate/2016051621405358-create-comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
3 changes: 2 additions & 1 deletion test/test-app/db/migrate/2016051621434009-create-posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
3 changes: 2 additions & 1 deletion test/test-app/db/migrate/2016061214092135-create-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export function up(schema) {
.notNullable();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down
3 changes: 2 additions & 1 deletion test/test-app/db/migrate/2016092015442134-create-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export function up(schema) {
.index();

table.timestamps();
table.index(['created_at', 'updated_at']);
table.index('created_at');
table.index('updated_at');
});
}

Expand Down

0 comments on commit ebbcf57

Please sign in to comment.