Compare commits
3 Commits
1c9d89946a
...
462782b14b
Author | SHA1 | Date | |
---|---|---|---|
462782b14b | |||
63c84a4b87 | |||
7603575aa9 |
18
postgres/40-views.sql
Normal file
18
postgres/40-views.sql
Normal file
@ -0,0 +1,18 @@
|
||||
create or replace view "user_rigths_per_channel" as
|
||||
select distinct
|
||||
"u"."id" as "user_id",
|
||||
"c"."id" as "channel_id",
|
||||
"c"."name" as "channel_name",
|
||||
"c"."description" as "channel_description",
|
||||
"r"."rights"
|
||||
from
|
||||
"user" "u"
|
||||
join
|
||||
"role_binding" "rb" on "u"."id" = "rb"."user_id"
|
||||
join
|
||||
"role" "ro" on "rb"."role_id" = "ro"."id"
|
||||
join
|
||||
"right" "r" on "ro"."id" = "r"."role_id"
|
||||
join
|
||||
"channel" "c" on "r"."channel_id" = "c"."id"
|
||||
order by "user_id";
|
48
postgres/99-sample.sql
Normal file
48
postgres/99-sample.sql
Normal file
@ -0,0 +1,48 @@
|
||||
-- More users
|
||||
insert into "user" ("username", "password_hash", "status", "picture", "bio")
|
||||
values
|
||||
('alice', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Online', 'https://example.com/alice.jpg', 'Loves coding and coffee.'),
|
||||
('bob', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Away', 'https://example.com/bob.jpg', 'Gamer and tech enthusiast.'),
|
||||
('charlie', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Busy', 'https://example.com/charlie.jpg', 'Database aficionado.'),
|
||||
('diana', '$2a$12$FChbwNEIH9imtkTAkNq35eqMb.1C.1BP3bbuFZwOr7rOrs5luwCzq', 'Online', 'https://example.com/diana.jpg', 'Enjoys reading and hiking.');
|
||||
|
||||
-- More roles
|
||||
insert into "role" ("name")
|
||||
values
|
||||
('moderator'),
|
||||
('guest');
|
||||
|
||||
-- More channels
|
||||
call add_channel('general', 'General discussion channel');
|
||||
call add_channel('development', 'Channel for development topics');
|
||||
call add_channel('random', 'Anything goes in here');
|
||||
|
||||
-- Role bindings for new users
|
||||
insert into "role_binding" ("user_id", "role_id")
|
||||
values
|
||||
((select "id" from "user" where "username" = 'alice'), (select "id" from "role" where "name" = 'member')),
|
||||
((select "id" from "user" where "username" = 'bob'), (select "id" from "role" where "name" = 'member')),
|
||||
((select "id" from "user" where "username" = 'charlie'), (select "id" from "role" where "name" = 'moderator')),
|
||||
((select "id" from "user" where "username" = 'diana'), (select "id" from "role" where "name" = 'guest'));
|
||||
|
||||
-- Rights for new roles and channels
|
||||
insert into "right" ("role_id", "channel_id", "rights")
|
||||
values
|
||||
((select "id" from "role" where "name" = 'moderator'), (select "id" from "channel" where "name" = 'general'), 'RW'),
|
||||
((select "id" from "role" where "name" = 'moderator'), (select "id" from "channel" where "name" = 'development'), 'RW'),
|
||||
((select "id" from "role" where "name" = 'guest'), (select "id" from "channel" where "name" = 'general'), 'R'),
|
||||
((select "id" from "role" where "name" = 'member'), (select "id" from "channel" where "name" = 'general'), 'RW'),
|
||||
((select "id" from "role" where "name" = 'member'), (select "id" from "channel" where "name" = 'development'), 'RW'),
|
||||
((select "id" from "role" where "name" = 'member'), (select "id" from "channel" where "name" = 'random'), 'RW');
|
||||
|
||||
|
||||
-- Sample messages
|
||||
insert into "message" ("sender_id", "channel_id", "content")
|
||||
values
|
||||
((select "id" from "user" where "username" = 'alice'), (select "id" from "channel" where "name" = 'general'), 'Hey everyone, glad to be here!'),
|
||||
((select "id" from "user" where "username" = 'bob'), (select "id" from "channel" where "name" = 'default'), 'Good morning!'),
|
||||
((select "id" from "user" where "username" = 'charlie'), (select "id" from "channel" where "name" = 'development'), 'Working on a new feature, updates coming soon.'),
|
||||
((select "id" from "user" where "username" = 'alice'), (select "id" from "channel" where "name" = 'general'), 'Does anyone have experience with PostgreSQL?'),
|
||||
((select "id" from "user" where "username" = 'diana'), (select "id" from "channel" where "name" = 'general'), 'Hello! Just joined the server.'),
|
||||
((select "id" from "user" where "username" = 'bob'), (select "id" from "channel" where "name" = 'random'), 'Anyone up for some gaming later?'),
|
||||
((select "id" from "user" where "username" = 'admin'), (select "id" from "channel" where "name" = 'default'), 'Welcome all new users!');
|
@ -1,4 +1,4 @@
|
||||
user default off
|
||||
|
||||
user admin on >admin allcommands allkeys
|
||||
user readonly on >readonly ~* +@read
|
||||
user admin on >admin allcommands allkeys &*
|
||||
user readonly on >readonly ~* +@read &*
|
Loading…
Reference in New Issue
Block a user