Skip to content

Commit

Permalink
constrain on table app_locale
Browse files Browse the repository at this point in the history
  • Loading branch information
mothsART committed Nov 27, 2022
1 parent a8974fa commit 6883d4a
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 49 deletions.
2 changes: 2 additions & 0 deletions migrations/2022-11-26-190715_app_locale/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ CREATE TABLE app_locale (
locale_id INTEGER NOT NULL,

UNIQUE(id)
UNIQUE(app_id, locale_id)

FOREIGN KEY (app_id) REFERENCES app (id)
FOREIGN KEY (locale_id) REFERENCES locale (id)
)
137 changes: 88 additions & 49 deletions src/db/populate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ impl PopulateDb for DesktopDDb {
.execute(connection)?;

let mut app_id = 0;

let mut constrain_app_locale = HashSet::new();

let mut constrain_app_keywords = HashSet::new();
let mut constrain_locale_keywords = HashSet::new();

let mut constrain_app_comments = HashSet::new();
let mut constrain_locale_comments = HashSet::new();

Expand Down Expand Up @@ -96,13 +100,18 @@ impl PopulateDb for DesktopDDb {
constrain_app_keywords.insert(app_hash);
constrain_locale_keywords.insert(locale_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
let a_l_hash = format!("{}_{}", app_id, _locale_id);
if !constrain_app_locale.contains(&a_l_hash) {
constrain_app_locale.insert(a_l_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
}

let default_comment = NewKeywords {
key: &d.default_name,
Expand All @@ -126,13 +135,18 @@ impl PopulateDb for DesktopDDb {
constrain_app_keywords.insert(app_hash);
constrain_locale_keywords.insert(locale_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
let a_l_hash = format!("{}_{}", app_id, _locale_id);
if !constrain_app_locale.contains(&a_l_hash) {
constrain_app_locale.insert(a_l_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
}

let keyword = NewKeywords {
key: &n.1,
Expand All @@ -156,13 +170,18 @@ impl PopulateDb for DesktopDDb {
constrain_app_keywords.insert(app_hash);
constrain_locale_keywords.insert(locale_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
let a_l_hash = format!("{}_{}", app_id, _locale_id);
if !constrain_app_locale.contains(&a_l_hash) {
constrain_app_locale.insert(a_l_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
}

let keyword = NewKeywords {
key: &g.1,
Expand All @@ -186,13 +205,18 @@ impl PopulateDb for DesktopDDb {
constrain_app_comments.insert(app_hash);
constrain_locale_comments.insert(locale_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
let a_l_hash = format!("{}_{}", app_id, _locale_id);
if !constrain_app_locale.contains(&a_l_hash) {
constrain_app_locale.insert(a_l_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
}

let default_comment = NewComments {
title: d_comment,
Expand All @@ -216,13 +240,18 @@ impl PopulateDb for DesktopDDb {
constrain_app_comments.insert(app_hash);
constrain_locale_comments.insert(locale_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
let a_l_hash = format!("{}_{}", app_id, _locale_id);
if !constrain_app_locale.contains(&a_l_hash) {
constrain_app_locale.insert(a_l_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
}

let comment = NewComments {
title: &c.1,
Expand All @@ -246,13 +275,18 @@ impl PopulateDb for DesktopDDb {
constrain_app_keywords.insert(app_hash);
constrain_locale_keywords.insert(locale_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
let a_l_hash = format!("{}_{}", app_id, _locale_id);
if !constrain_app_locale.contains(&a_l_hash) {
constrain_app_locale.insert(a_l_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
}

let keyword = NewKeywords {
key: &k,
Expand All @@ -277,13 +311,18 @@ impl PopulateDb for DesktopDDb {
constrain_app_keywords.insert(app_hash);
constrain_locale_keywords.insert(locale_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
let a_l_hash = format!("{}_{}", app_id, _locale_id);
if !constrain_app_locale.contains(&a_l_hash) {
constrain_app_locale.insert(a_l_hash);

let a_l = NewAppLocale {
app_id: app_id as i32,
locale_id: *_locale_id,
};
diesel::insert_into(app_locale::table)
.values(&a_l)
.execute(connection)?;
}

let keyword = NewKeywords {
key: &k,
Expand Down

0 comments on commit 6883d4a

Please sign in to comment.