diff --git a/migrations/20230716212933_create_role_name_function.down.sql b/migrations/20230716212933_create_role_name_function.down.sql new file mode 100644 index 0000000..0335b43 --- /dev/null +++ b/migrations/20230716212933_create_role_name_function.down.sql @@ -0,0 +1,2 @@ +-- Add down migration script here +DROP FUNCTION IF EXISTS role_name(INT, INT); diff --git a/migrations/20230716212933_create_role_name_function.up.sql b/migrations/20230716212933_create_role_name_function.up.sql new file mode 100644 index 0000000..3846b1a --- /dev/null +++ b/migrations/20230716212933_create_role_name_function.up.sql @@ -0,0 +1,17 @@ +-- Add up migration script here +CREATE FUNCTION role_name(role_id INT, lang_id INT) +RETURNS TEXT +AS $$ +SELECT + COALESCE( + MAX(a.name), + MAX(b.name), + MAX(c.name + )) AS name +FROM roles +LEFT JOIN role_names a ON a.role = roles.id AND a.language = lang_id +LEFT JOIN role_names b ON b.role = roles.id AND b.language = 1 +LEFT JOIN role_names c ON c.role = roles.id +WHERE roles.id = role_id +GROUP BY roles.id; +$$ LANGUAGE SQL; diff --git a/migrations/20230716213851_add_users.down.sql b/migrations/20230716213851_add_users.down.sql new file mode 100644 index 0000000..e4f50bf --- /dev/null +++ b/migrations/20230716213851_add_users.down.sql @@ -0,0 +1,3 @@ +-- Add down migration script here +DELETE FROM users + WHERE id=1; diff --git a/migrations/20230716213851_add_users.up.sql b/migrations/20230716213851_add_users.up.sql new file mode 100644 index 0000000..04437dc --- /dev/null +++ b/migrations/20230716213851_add_users.up.sql @@ -0,0 +1,6 @@ +-- Add up migration script here +-- admin/admin login +INSERT INTO users + (id, user_name, pass_hash) +VALUES + (1, 'admin', '$2y$10$eoghV7BDZSDDKAjjYuESUuMwl3IqFBzawFybgkBKWl.CKlI6jXAQ.');