Skip to content

Commit fb78828

Browse files
committed
Created persistent sessions table.
Unfortunately, due to diesel-rs/diesel#2411, the table can't be named `sessions` as it causes patch conflicts with recent_crate_downloads.
1 parent e8a2cd0 commit fb78828

File tree

4 files changed

+111
-18
lines changed

4 files changed

+111
-18
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP TABLE persistent_sessions;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE TABLE persistent_sessions
2+
(
3+
id SERIAL
4+
CONSTRAINT persistent_sessions_pk
5+
PRIMARY KEY,
6+
user_id INTEGER NOT NULL
7+
CONSTRAINT persistent_sessions_users_id_fk
8+
REFERENCES users
9+
ON UPDATE CASCADE ON DELETE CASCADE,
10+
hashed_token bytea NOT NULL,
11+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
12+
last_used_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
13+
revoked BOOLEAN DEFAULT FALSE NOT NULL,
14+
last_ip_address inet NOT NULL,
15+
last_user_agent VARCHAR NOT NULL
16+
);
17+
18+
COMMENT ON TABLE persistent_sessions IS 'This table contains the hashed tokens for all of the cookie-based persistent sessions';
19+
20+
CREATE INDEX persistent_sessions_user_id_index
21+
ON persistent_sessions (user_id);

src/schema.rs

Lines changed: 79 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,65 @@ table! {
598598
}
599599
}
600600

601+
table! {
602+
use diesel::sql_types::*;
603+
use diesel_full_text_search::{TsVector as Tsvector};
604+
605+
/// Representation of the `persistent_sessions` table.
606+
///
607+
/// (Automatically generated by Diesel.)
608+
persistent_sessions (id) {
609+
/// The `id` column of the `persistent_sessions` table.
610+
///
611+
/// Its SQL type is `Int4`.
612+
///
613+
/// (Automatically generated by Diesel.)
614+
id -> Int4,
615+
/// The `user_id` column of the `persistent_sessions` table.
616+
///
617+
/// Its SQL type is `Int4`.
618+
///
619+
/// (Automatically generated by Diesel.)
620+
user_id -> Int4,
621+
/// The `hashed_token` column of the `persistent_sessions` table.
622+
///
623+
/// Its SQL type is `Bytea`.
624+
///
625+
/// (Automatically generated by Diesel.)
626+
hashed_token -> Bytea,
627+
/// The `created_at` column of the `persistent_sessions` table.
628+
///
629+
/// Its SQL type is `Timestamp`.
630+
///
631+
/// (Automatically generated by Diesel.)
632+
created_at -> Timestamp,
633+
/// The `last_used_at` column of the `persistent_sessions` table.
634+
///
635+
/// Its SQL type is `Timestamp`.
636+
///
637+
/// (Automatically generated by Diesel.)
638+
last_used_at -> Timestamp,
639+
/// The `revoked` column of the `persistent_sessions` table.
640+
///
641+
/// Its SQL type is `Bool`.
642+
///
643+
/// (Automatically generated by Diesel.)
644+
revoked -> Bool,
645+
/// The `last_ip_address` column of the `persistent_sessions` table.
646+
///
647+
/// Its SQL type is `Inet`.
648+
///
649+
/// (Automatically generated by Diesel.)
650+
last_ip_address -> Inet,
651+
/// The `last_user_agent` column of the `persistent_sessions` table.
652+
///
653+
/// Its SQL type is `Varchar`.
654+
///
655+
/// (Automatically generated by Diesel.)
656+
last_user_agent -> Varchar,
657+
}
658+
}
659+
601660
table! {
602661
use diesel::sql_types::*;
603662
use diesel_full_text_search::{TsVector as Tsvector};
@@ -627,6 +686,24 @@ table! {
627686
}
628687
}
629688

689+
table! {
690+
/// Representation of the `recent_crate_downloads` view.
691+
///
692+
/// This data represents the downloads in the last 90 days.
693+
/// This view does not contain realtime data.
694+
/// It is refreshed by the `update-downloads` script.
695+
recent_crate_downloads (crate_id) {
696+
/// The `crate_id` column of the `recent_crate_downloads` view.
697+
///
698+
/// Its SQL type is `Integer`.
699+
crate_id -> Integer,
700+
/// The `downloads` column of the `recent_crate_downloads` table.
701+
///
702+
/// Its SQL type is `BigInt`.
703+
downloads -> BigInt,
704+
}
705+
}
706+
630707
table! {
631708
use diesel::sql_types::*;
632709
use diesel_full_text_search::{TsVector as Tsvector};
@@ -679,24 +756,6 @@ table! {
679756
}
680757
}
681758

682-
table! {
683-
/// Representation of the `recent_crate_downloads` view.
684-
///
685-
/// This data represents the downloads in the last 90 days.
686-
/// This view does not contain realtime data.
687-
/// It is refreshed by the `update-downloads` script.
688-
recent_crate_downloads (crate_id) {
689-
/// The `crate_id` column of the `recent_crate_downloads` view.
690-
///
691-
/// Its SQL type is `Integer`.
692-
crate_id -> Integer,
693-
/// The `downloads` column of the `recent_crate_downloads` table.
694-
///
695-
/// Its SQL type is `BigInt`.
696-
downloads -> BigInt,
697-
}
698-
}
699-
700759
table! {
701760
use diesel::sql_types::*;
702761
use diesel_full_text_search::{TsVector as Tsvector};
@@ -1023,6 +1082,7 @@ joinable!(dependencies -> versions (version_id));
10231082
joinable!(emails -> users (user_id));
10241083
joinable!(follows -> crates (crate_id));
10251084
joinable!(follows -> users (user_id));
1085+
joinable!(persistent_sessions -> users (user_id));
10261086
joinable!(publish_limit_buckets -> users (user_id));
10271087
joinable!(publish_rate_overrides -> users (user_id));
10281088
joinable!(readme_renderings -> versions (version_id));
@@ -1050,6 +1110,7 @@ allow_tables_to_appear_in_same_query!(
10501110
follows,
10511111
keywords,
10521112
metadata,
1113+
persistent_sessions,
10531114
publish_limit_buckets,
10541115
publish_rate_overrides,
10551116
readme_renderings,

src/worker/dump_db/dump-db.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ created_at = "public"
136136
[metadata.columns]
137137
total_downloads = "public"
138138

139+
[persistent_sessions.columns]
140+
id = "private"
141+
user_id = "private"
142+
hashed_token = "private"
143+
created_at = "private"
144+
last_used_at = "private"
145+
revoked = "private"
146+
last_ip_address = "private"
147+
last_user_agent = "private"
148+
139149
[publish_limit_buckets.columns]
140150
user_id = "private"
141151
tokens = "private"

0 commit comments

Comments
 (0)