Previous: , Up: PostgreSQL Setup   [Contents][Index]


4.4 Creating an Initial Admin User

An initial admin user needs to be created in the database. Thereafter, that user maintains other users using the web application. Creating the initial admin user fundamentally consists of making entries in the usertable, role and user_role tables.

Firstly, create the entries in the role table by running the following script using psql:

INSERT INTO role (name) VALUES ('Admin'), ('User');

An initial admin user can be created similarly to the following, replacing each value appropriately:

INSERT INTO usertable (firstname, lastname, email, uuid, password, nickname)
VALUES ('admin', '', 'admin@trip.test', gen_random_uuid(),
crypt('SECRET', gen_salt('bf')), 'admin');

INSERT INTO user_role (user_id, role_id)
VALUES (
(SELECT id FROM usertable u WHERE u.nickname='admin'),
(SELECT id FROM role WHERE name='Admin')
);