Add a table for mail aliases
This commit is contained in:
parent
026374fd7c
commit
5cd7f26717
2 changed files with 15 additions and 3 deletions
8
migrations/20230829163818_aliases.sql
Normal file
8
migrations/20230829163818_aliases.sql
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
-- Add migration script here
|
||||
ALTER TABLE emails ADD COLUMN alias BOOLEAN NOT NULL DEFAULT false;
|
||||
|
||||
CREATE TABLE alias_recipient (
|
||||
mail TEXT REFERENCES emails(mail) NOT NULL,
|
||||
recipient TEXT NOT NULL,
|
||||
PRIMARY KEY (mail, recipient)
|
||||
);
|
||||
10
src/main.rs
10
src/main.rs
|
|
@ -505,9 +505,13 @@ async fn home(
|
|||
User(user): User,
|
||||
Query(query): Query<HomeQuery>,
|
||||
) -> Result<Html<String>, Error> {
|
||||
let mails = sqlx::query_as!(Mail, "SELECT mail FROM emails WHERE id = $1", user)
|
||||
.fetch_all(&state.db)
|
||||
.await?;
|
||||
let mails = sqlx::query_as!(
|
||||
Mail,
|
||||
"SELECT mail FROM emails WHERE id = $1 AND alias = false",
|
||||
user
|
||||
)
|
||||
.fetch_all(&state.db)
|
||||
.await?;
|
||||
|
||||
let mut context = tera::Context::new();
|
||||
context.insert("mails", &mails);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue