Skip to content

Commit 1c07e2c

Browse files
committed
clean up migration -> use uuid
1 parent 54cb993 commit 1c07e2c

7 files changed

+26
-31
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class EnableExtensionForUuid < ActiveRecord::Migration[6.0]
2+
def change
3+
enable_extension 'pgcrypto' unless extension_enabled?('pgcrypto')
4+
end
5+
end

db/migrate/20190209163712_devise_create_users.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

3-
class DeviseCreateUsers < ActiveRecord::Migration[5.2]
3+
class DeviseCreateUsers < ActiveRecord::Migration[6.0]
44
def change
5-
create_table :users do |t|
5+
create_table :users, id: :uuid do |t|
66

77
## General
88
t.string 'first_name', null: false, default: ''
@@ -37,8 +37,8 @@ def change
3737
t.string :unlock_token # Only if unlock strategy is :email or :both
3838
t.datetime :locked_at
3939

40-
## JTI for JWT auth
41-
t.string :jti, null: false
40+
## Refresh token for JWT auth
41+
t.string :refresh_token
4242

4343
# role attributes (used as enum in user model)
4444
t.integer :role, default: 0, null: false
@@ -50,7 +50,7 @@ def change
5050
add_index :users, :reset_password_token, unique: true
5151
add_index :users, :confirmation_token, unique: true
5252
add_index :users, :unlock_token, unique: true
53-
add_index 'users', ['jti'], name: 'index_users_on_jti', unique: true, using: :btree
53+
add_index 'users', ['refresh_token'], name: 'index_users_on_refresh_token', unique: true, using: :btree
5454

5555
end
5656
end

db/migrate/20200105201236_add_foreign_key_constraint_to_active_storage_attachments_for_blob_id.active_storage.rb

Lines changed: 0 additions & 10 deletions
This file was deleted.

db/migrate/20200911092211_create_active_storage_tables.active_storage.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# This migration comes from active_storage (originally 20170806125915)
2-
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
1+
# frozen_string_literal: true
2+
3+
class CreateActiveStorageTables < ActiveRecord::Migration[6.0]
34
def change
45
create_table :active_storage_blobs do |t|
56
t.string :key, null: false

db/migrate/20200911092212_add_refresh_token_to_user.graph_ql_auth.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

db/schema.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2020_09_11_092212) do
13+
ActiveRecord::Schema.define(version: 2020_09_11_092211) do
1414

1515
# These are extensions that must be enabled in order to support this database
16+
enable_extension "pgcrypto"
1617
enable_extension "plpgsql"
1718

1819
create_table "active_storage_attachments", force: :cascade do |t|
@@ -36,7 +37,7 @@
3637
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
3738
end
3839

39-
create_table "users", force: :cascade do |t|
40+
create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
4041
t.string "first_name", default: "", null: false
4142
t.string "last_name", default: "", null: false
4243
t.string "email", default: "", null: false
@@ -56,12 +57,13 @@
5657
t.integer "failed_attempts", default: 0, null: false
5758
t.string "unlock_token"
5859
t.datetime "locked_at"
59-
t.integer "role", default: 0, null: false
60-
t.datetime "created_at", null: false
61-
t.datetime "updated_at", null: false
6260
t.string "refresh_token"
61+
t.integer "role", default: 0, null: false
62+
t.datetime "created_at", precision: 6, null: false
63+
t.datetime "updated_at", precision: 6, null: false
6364
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
6465
t.index ["email"], name: "index_users_on_email", unique: true
66+
t.index ["refresh_token"], name: "index_users_on_refresh_token", unique: true
6567
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
6668
t.index ["unlock_token"], name: "index_users_on_unlock_token", unique: true
6769
end

db/seeds.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
User.create(
1+
user = User.create(
22
email: ENV['ADMIN_EMAIL'],
33
password: ENV['ADMIN_PASSWORD'],
44
password_confirmation: ENV['ADMIN_PASSWORD'],
55
first_name: ENV['ADMIN_FIRST_NAME'],
66
last_name: ENV['ADMIN_LAST_NAME'],
7-
role: 'admin'
7+
role: 'superadmin'
88
)
9+
10+
if user
11+
Rails.logger.info "Login with #{ENV['ADMIN_EMAIL']} and #{ENV['ADMIN_PASSWORD']}"
12+
end

0 commit comments

Comments
 (0)