diff --git a/README.md b/README.md index a182bbe..da6a403 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,15 @@ npm install --save docker-compose -f ./docker/DB-docker-compose.yml --env-file ./deploy/env/postgresql.env down ```
+- DB Migration + - install migration tool + ```bash + npm install knex -g + ``` + - Run migration + ```bash + knex migrate:latest + ```
## Test Commands diff --git a/deploy/dbMigrations/20230301144748_init_tables.js b/deploy/dbMigrations/20230301144748_add_account_table.js similarity index 50% rename from deploy/dbMigrations/20230301144748_init_tables.js rename to deploy/dbMigrations/20230301144748_add_account_table.js index c7cfa7c..b5d8664 100644 --- a/deploy/dbMigrations/20230301144748_init_tables.js +++ b/deploy/dbMigrations/20230301144748_add_account_table.js @@ -1,21 +1,25 @@ exports.up = (knex) => { - return knex.schema.createTable('tbl_account', (table)=>{ - table.uuid('id').notNullable().primary() + return knex.schema.dropTableIfExists('tbl_account').createTable('tbl_account', (table)=>{ + table.uuid('id').notNullable().primary().index('tbl_account_id_index') table.string('firstname', 50) table.string('lastname', 50) + table.string('nickname', 50) table.string('email', 64) table.string('mobile', 64) - table.string('country', 2) - table.string('oauth_type', 5).notNullable().index('user_oauth_type_index') - table.string('oauth_id', 512) + table.string('country', 2).defaultTo('KR') + table.string('oauth_type', 5).notNullable().index('tbl_account_oauth_type_index') + table.string('oauth_id', 512).index('tbl_account_oauth_id_index') table.string('pin', 64).defaultTo('0000') + table.integer('target_read_time').notNullable().defaultTo(3600) table.timestamp('pin_created_at') table.boolean('email_verification').defaultTo(false) table.timestamp('email_verification_date') table.boolean('age_verification').defaultTo(false) table.timestamp('age_verification_date') - table.jsonb('meta') + table.string('profile_image_url', 2048) + table.jsonb('bg_image_urls', 2048).notNullable().defaultTo(JSON.stringify([])) + table.jsonb('meta').notNullable().defaultTo(JSON.stringify({})) table.timestamp('created_at').defaultTo(knex.fn.now()) table.timestamp('updated_at').defaultTo(knex.fn.now()) table.timestamp('deleted_at') diff --git a/deploy/dbMigrations/20230311173534_add_mybook_table.js b/deploy/dbMigrations/20230311173534_add_mybook_table.js new file mode 100644 index 0000000..0fead28 --- /dev/null +++ b/deploy/dbMigrations/20230311173534_add_mybook_table.js @@ -0,0 +1,27 @@ + +exports.up = (knex) => { + return knex.schema.dropTableIfExists('tbl_mybook').createTable('tbl_mybook', (table)=>{ + table.uuid('id').notNullable().primary().index('tbl_mybook_id_index') + table.uuid('user_id').notNullable().index('tbl_mybook_user_id_index') + table.string('title', 255).notNullable() + table.text('content') + table.jsonb('authors').defaultTo(JSON.stringify([])) + table.jsonb('translators').defaultTo(JSON.stringify([])) + table.string('publisher') + table.string('thumbnail_url') + table.string('isbn').notNullable() + table.integer('current_page').defaultTo(0) + table.integer('total_page').defaultTo(1) + table.jsonb('images').notNullable().defaultTo(JSON.stringify([])) + table.boolean('reading').defaultTo(false) + table.boolean('favorite').defaultTo(false).index('tbl_mybook_favorite_index') + table.jsonb('meta').notNullable().defaultTo(JSON.stringify({})) + table.timestamp('created_at').defaultTo(knex.fn.now()) + table.timestamp('updated_at').defaultTo(knex.fn.now()) + table.timestamp('deleted_at') + }) +} + +exports.down = (knex)=>{ + return knex.schema.dropTable('tbl_mybook') +} \ No newline at end of file diff --git a/deploy/dbMigrations/20230311175534_add_myhistory_table.js b/deploy/dbMigrations/20230311175534_add_myhistory_table.js new file mode 100644 index 0000000..c9e3c13 --- /dev/null +++ b/deploy/dbMigrations/20230311175534_add_myhistory_table.js @@ -0,0 +1,16 @@ + +exports.up = (knex) => { + return knex.schema.dropTableIfExists('tbl_myhistory').createTable('tbl_myhistory', (table)=>{ + table.uuid('id').notNullable().primary().index('tbl_myhistory_id_index') + table.uuid('user_id').notNullable().index('tbl_myhistory_user_id_index') + table.uuid('mybook_id').notNullable().index('tbl_myhistory_mybook_id_index') + table.integer('reading_time').notNullable().defaultTo(0) + table.timestamp('created_at').defaultTo(knex.fn.now()).index('tbl_myhistory_created_at_index') + table.timestamp('updated_at').defaultTo(knex.fn.now()).index('tbl_myhistory_updated_at_index') + table.timestamp('deleted_at') + }) +} + +exports.down = (knex)=>{ + return knex.schema.dropTable('tbl_myhistory') +} \ No newline at end of file