-
Make a database migration (knex .js file) in here
-
Use this code to create ‘created_at’ and ‘updated_at’ columns
.table('TABLENAME_HERE', function (table) {
table.timestamp('created_at').defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table.timestamp('updated_at').defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
})
- Add the ‘exports.down’ part, see full example code:
exports.up = function (knex) {
return knex.schema
.table('courses_lectures_ratings_users', function (table) {
table.timestamp('created_at').defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table.timestamp('updated_at').defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
})
.table('courses_lectures_bookmarks_users', function (table) {
table.timestamp('created_at').defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table.timestamp('updated_at').defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
})
.table('courses_lectures_users_progress', function (table) {
table.timestamp('created_at').defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table.timestamp('updated_at').defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
})
.table('schools_notifications', function (table) {
table.timestamp('created_at').defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table.timestamp('updated_at').defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
})
.table('release_notes', function (table) {
table.timestamp('created_at').defaultTo(knex.raw('CURRENT_TIMESTAMP'));
table.timestamp('updated_at').defaultTo(knex.raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
})
};
exports.down = function (knex) {
return knex.schema
.table('courses_lectures_ratings_users', function (table) {
table.dropColumn('created_at');
table.dropColumn('updated_at');
})
.table('courses_lectures_bookmarks_users', function (table) {
table.dropColumn('created_at');
table.dropColumn('updated_at');
})
.table('courses_lectures_users_progress', function (table) {
table.dropColumn('created_at');
table.dropColumn('updated_at');
})
.table('schools_notifications', function (table) {
table.dropColumn('created_at');
table.dropColumn('updated_at');
})
.table('release_notes', function (table) {
table.dropColumn('created_at');
table.dropColumn('updated_at');
})
};
-
Save your file, do a full refresh of wappler (control + R) and it should show in the changes
-
Right click, apply this change
-
Voila! You have 2 new columns
Note: Wappler db manager doesn’t show the actual time stamp, you can use a different db manager to confirm
Community Page
Last updated:
Last updated: