switch install state to db

This commit is contained in:
2026-01-23 12:20:13 +01:00
parent 965e8cdffe
commit dea0ef508a
6 changed files with 32 additions and 12 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ When translators disagree on a translation or want to suggest alternatives (regi
## Setup / First User ## Setup / First User
When the file `.installed` is missing, the `/setup` route is accessible for creating the initial admin account. The first user created will be the system's default contact email (accessible via `User.first.email`). When setup has not been completed, the `/setup` route is accessible for creating the initial admin account. Completion is tracked in the database. The first user created will be the system's default contact email (accessible via `User.first.email`).
For detailed setup instructions, see [SETUP_GUIDE.md](docs/SETUP_GUIDE.md). For detailed setup instructions, see [SETUP_GUIDE.md](docs/SETUP_GUIDE.md).
+1 -1
View File
@@ -57,6 +57,6 @@ class ApplicationController < ActionController::Base
end end
def setup_completed? def setup_completed?
File.exist?(Rails.root.join(".installed")) SetupState.installed?
end end
end end
+2 -10
View File
@@ -11,7 +11,7 @@ class SetupController < ApplicationController
@user.invitation_accepted_at = Time.current @user.invitation_accepted_at = Time.current
if @user.save if @user.save
create_installed_marker SetupState.mark_installed!
session[:user_id] = @user.id session[:user_id] = @user.id
redirect_to admin_root_path, notice: "Setup complete! Welcome to Sanasto Wiki." redirect_to admin_root_path, notice: "Setup complete! Welcome to Sanasto Wiki."
else else
@@ -28,15 +28,7 @@ class SetupController < ApplicationController
end end
def setup_completed? def setup_completed?
File.exist?(installed_marker_path) SetupState.installed?
end
def installed_marker_path
Rails.root.join(".installed")
end
def create_installed_marker
FileUtils.touch(installed_marker_path)
end end
def user_params def user_params
+16
View File
@@ -0,0 +1,16 @@
class SetupState < ApplicationRecord
def self.installed?
first&.installed? || false
end
def self.mark_installed!
record = first_or_initialize
record.installed = true
record.installed_at ||= Time.current
record.save!
end
def self.reset!
delete_all
end
end
@@ -0,0 +1,10 @@
class CreateSetupStates < ActiveRecord::Migration[8.1]
def change
create_table :setup_states do |t|
t.boolean :installed, null: false, default: false
t.datetime :installed_at
t.timestamps
end
end
end
+2
View File
@@ -88,7 +88,9 @@ BEGIN
INSERT INTO entries_fts(entries_fts, rowid, fi, en, sv, no, ru, de, notes) INSERT INTO entries_fts(entries_fts, rowid, fi, en, sv, no, ru, de, notes)
VALUES('delete', old.id, old.fi, old.en, old.sv, old.no, old.ru, old.de, old.notes); VALUES('delete', old.id, old.fi, old.en, old.sv, old.no, old.ru, old.de, old.notes);
END; END;
CREATE TABLE IF NOT EXISTS "setup_states" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "installed" boolean DEFAULT FALSE NOT NULL, "installed_at" datetime(6), "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL);
INSERT INTO "schema_migrations" (version) VALUES INSERT INTO "schema_migrations" (version) VALUES
('20260122131000'),
('20260122130000'), ('20260122130000'),
('20260122124151'), ('20260122124151'),
('20260122123837'), ('20260122123837'),