1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::error::Result;
use rusqlite::Connection;

pub const ADDRESS_COMMON_COLS: &str = "
    guid,
    given_name,
    additional_name,
    family_name,
    organization,
    street_address,
    address_level3,
    address_level2,
    address_level1,
    postal_code,
    country,
    tel,
    email,
    time_created,
    time_last_used,
    time_last_modified,
    times_used,
    sync_change_counter";

pub const CREDIT_CARD_COMMON_COLS: &str = "
    guid,
    cc_name,
    cc_number,
    cc_exp_month,
    cc_exp_year,
    cc_type,
    time_created,
    time_last_used,
    time_last_modified,
    times_used,
    sync_change_counter";

#[allow(dead_code)]
const CREATE_SHARED_SCHEMA_SQL: &str = include_str!("../sql/create_shared_schema.sql");
const CREATE_SHARED_TRIGGERS_SQL: &str = include_str!("../sql/create_shared_triggers.sql");

#[allow(dead_code)]
pub fn init(db: &Connection) -> Result<()> {
    create(db)?;
    Ok(())
}

#[allow(dead_code)]
fn create(db: &Connection) -> Result<()> {
    log::debug!("Creating schema");
    db.execute_batch(
        format!(
            "{}\n{}",
            CREATE_SHARED_SCHEMA_SQL, CREATE_SHARED_TRIGGERS_SQL
        )
        .as_str(),
    )?;

    Ok(())
}