You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
802 B
Rust
31 lines
802 B
Rust
4 years ago
|
use crate::database::role_permissions::RolePermissions;
|
||
|
use crate::database::Model;
|
||
|
use postgres::{Client, Error};
|
||
|
use std::sync::{Arc, Mutex};
|
||
|
|
||
|
#[derive(Clone)]
|
||
|
pub struct Roles {
|
||
|
connection: Arc<Mutex<Client>>,
|
||
|
role_permission: RolePermissions,
|
||
|
}
|
||
|
|
||
|
impl Model for Roles {
|
||
|
fn new(connection: Arc<Mutex<Client>>) -> Self {
|
||
|
Self {
|
||
|
role_permission: RolePermissions::new(Arc::clone(&connection)),
|
||
|
connection,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn init(&self) -> Result<(), Error> {
|
||
|
self.connection.lock().unwrap().batch_execute(
|
||
|
"
|
||
|
CREATE TABLE IF NOT EXISTS roles (
|
||
|
id SERIAL PRIMARY KEY,
|
||
|
name VARCHAR(128) UNIQUE NOT NULL,
|
||
|
description VARCHAR(512)
|
||
|
);",
|
||
|
)
|
||
|
}
|
||
|
}
|