Create admin user on app start, not in data migration

This commit is contained in:
James Smith committed 2023-07-06 10:31:45 +01:00
1 parent 714b3adec7
commit e509fe49cb
2 files changed
+11 -15

No files matched your search

+11
View File
@@ -21,5 +21,16 @@ module VanDam
# Don't generate system test files.
config.generators.system_tests = nil
config.after_initialize do
# Create default admin user if there aren't any users yet
if ActiveRecord::Base.connection.table_exists?("users") && User.count == 0
User.create(
username: "admin",
email: "nobody@example.com",
admin: true
)
end
end
end
end
@@ -1,15 +0,0 @@
# frozen_string_literal: true
class CreateDefaultAdminUser < ActiveRecord::Migration[7.0]
def up
User.create(
username: "admin",
email: "nobody@example.com",
admin: true
)
end
def down
User.find_by(username: "admin").destroy
end
end