Skip to content

Commit 99edf52

Browse files
committed
feat: imported users have importation date instead of registrataion date
- Now registration date is optional (we allow NULL) for imported users. - And imported users have an importation date, which is NULL for registered users throught the sdantadrd registration process.
1 parent 21174d4 commit 99edf52

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE torrust_users CHANGE date_registered date_registered DATETIME NOT NULL
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE torrust_users ADD COLUMN date_imported DATETIME DEFAULT NULL
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE TABLE IF NOT EXISTS torrust_users_new (
2+
user_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
3+
date_registered TEXT DEFAULT NULL,
4+
administrator BOOL NOT NULL DEFAULT FALSE
5+
);
6+
7+
INSERT INTO torrust_users_new SELECT * FROM torrust_users;
8+
9+
DROP TABLE torrust_users;
10+
11+
ALTER TABLE torrust_users_new RENAME TO torrust_users
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE torrust_users ADD COLUMN date_imported TEXT DEFAULT NULL

src/models/user.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use serde::{Deserialize, Serialize};
33
#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow)]
44
pub struct User {
55
pub user_id: i64,
6-
pub date_registered: String,
6+
pub date_registered: Option<String>,
7+
pub date_imported: Option<String>,
78
pub administrator: bool,
89
}
910

@@ -33,7 +34,8 @@ pub struct UserCompact {
3334
#[derive(Debug, Serialize, Deserialize, Clone, sqlx::FromRow)]
3435
pub struct UserFull {
3536
pub user_id: i64,
36-
pub date_registered: String,
37+
pub date_registered: Option<String>,
38+
pub date_imported: Option<String>,
3739
pub administrator: bool,
3840
pub username: String,
3941
pub email: String,

src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v2_0_0.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ impl SqliteDatabaseV2_0_0 {
6767
})
6868
}
6969

70-
pub async fn insert_user(
70+
pub async fn insert_imported_user(
7171
&self,
7272
user_id: i64,
73-
date_registered: &str,
73+
date_imported: &str,
7474
administrator: bool,
7575
) -> Result<i64, sqlx::Error> {
7676
query(
77-
"INSERT INTO torrust_users (user_id, date_registered, administrator) VALUES (?, ?, ?)",
77+
"INSERT INTO torrust_users (user_id, date_imported, administrator) VALUES (?, ?, ?)",
7878
)
7979
.bind(user_id)
80-
.bind(date_registered)
80+
.bind(date_imported)
8181
.bind(administrator)
8282
.execute(&self.pool)
8383
.await

src/upgrades/from_v1_0_0_to_v2_0_0/upgrader.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
//! NOTES for `torrust_users` table transfer:
44
//!
55
//! - In v2, the table `torrust_user` contains a field `date_registered` non existing in v1.
6-
//! It's used the day when the upgrade command is executed.
6+
//! We changed that columns to allow NULL. WE also added the new column `date_imported` with
7+
//! the datetime when the upgrader was executed.
78
//! - In v2, the table `torrust_user_profiles` contains two new fields: `bio` and `avatar`.
89
//! Empty string is used as default value.
910
@@ -129,10 +130,10 @@ async fn transfer_user_data(
129130
&user.user_id, &user.username
130131
);
131132

132-
let default_data_registered = today_iso8601();
133+
let date_imported = today_iso8601();
133134

134135
let id = dest_database
135-
.insert_user(user.user_id, &default_data_registered, user.administrator)
136+
.insert_imported_user(user.user_id, &date_imported, user.administrator)
136137
.await
137138
.unwrap();
138139

0 commit comments

Comments
 (0)