Skip to content

Commit

Permalink
simplify master table(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
tantaman committed Apr 24, 2023
1 parent 777b2da commit 28b6f4c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 41 deletions.
3 changes: 1 addition & 2 deletions core/src/consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

#define TBL_SITE_ID "__crsql_siteid"
#define TBL_DB_VERSION "__crsql_dbversion"
#define TBL_SCHEMA "__crsql_master"
#define TBL_SCHEMA_PROPS "__crsql_master_prop"
#define TBL_SCHEMA "crsql_master"
#define UNION "UNION"

#define MAX_TBL_NAME_LEN 2048
Expand Down
41 changes: 2 additions & 39 deletions core/src/crsqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ static int createSchemaTableIfNotExists(sqlite3 *db) {
}

char *zSql = sqlite3_mprintf(
"CREATE TABLE IF NOT EXISTS \"%s\" (id INTEGER PRIMARY KEY "
"AUTOINCREMENT, type TEXT NOT NULL, name TEXT NOT "
"NULL, augments TEXT NOT NULL) STRICT;",
"CREATE TABLE IF NOT EXISTS \"%s\" (\"key\" TEXT PRIMARY KEY, \"value\" "
"TEXT);",
TBL_SCHEMA);
rc = sqlite3_exec(db, zSql, 0, 0, 0);
sqlite3_free(zSql);
Expand All @@ -134,42 +133,6 @@ static int createSchemaTableIfNotExists(sqlite3 *db) {
return rc;
}

zSql = sqlite3_mprintf(
"CREATE UNIQUE INDEX IF NOT EXISTS __crsql_master_index ON "
"\"%s\" (type, name);",
TBL_SCHEMA);
rc = sqlite3_exec(db, zSql, 0, 0, 0);
sqlite3_free(zSql);

if (rc != SQLITE_OK) {
sqlite3_exec(db, "ROLLBACK;", 0, 0, 0);
return rc;
}

zSql = sqlite3_mprintf(
"CREATE TABLE IF NOT EXISTS \"%s\" (master_id INTEGER NOT NULL, key "
"TEXT NOT NULL, ord INTEGER DEFAULT 0, value ANY) STRICT;",
TBL_SCHEMA_PROPS);
rc = sqlite3_exec(db, zSql, 0, 0, 0);
sqlite3_free(zSql);

if (rc != SQLITE_OK) {
sqlite3_exec(db, "ROLLBACK;", 0, 0, 0);
return rc;
}

zSql = sqlite3_mprintf(
"CREATE UNIQUE INDEX IF NOT EXISTS __crsql_master_prop_id_index "
"ON \"%s\" (master_id, key, ord);",
TBL_SCHEMA_PROPS);
rc = sqlite3_exec(db, zSql, 0, 0, 0);
sqlite3_free(zSql);

if (rc != SQLITE_OK) {
sqlite3_exec(db, "ROLLBACK;", 0, 0, 0);
return rc;
}

sqlite3_exec(db, "RELEASE crsql_create_schema_table;", 0, 0, 0);

return rc;
Expand Down

0 comments on commit 28b6f4c

Please sign in to comment.