Skip to content

Commit 28b6f4c

Browse files
committed
simplify master table(s)
1 parent 777b2da commit 28b6f4c

File tree

2 files changed

+3
-41
lines changed

2 files changed

+3
-41
lines changed

core/src/consts.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626
#define TBL_SITE_ID "__crsql_siteid"
2727
#define TBL_DB_VERSION "__crsql_dbversion"
28-
#define TBL_SCHEMA "__crsql_master"
29-
#define TBL_SCHEMA_PROPS "__crsql_master_prop"
28+
#define TBL_SCHEMA "crsql_master"
3029
#define UNION "UNION"
3130

3231
#define MAX_TBL_NAME_LEN 2048

core/src/crsqlite.c

+2-39
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ static int createSchemaTableIfNotExists(sqlite3 *db) {
122122
}
123123

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

137-
zSql = sqlite3_mprintf(
138-
"CREATE UNIQUE INDEX IF NOT EXISTS __crsql_master_index ON "
139-
"\"%s\" (type, name);",
140-
TBL_SCHEMA);
141-
rc = sqlite3_exec(db, zSql, 0, 0, 0);
142-
sqlite3_free(zSql);
143-
144-
if (rc != SQLITE_OK) {
145-
sqlite3_exec(db, "ROLLBACK;", 0, 0, 0);
146-
return rc;
147-
}
148-
149-
zSql = sqlite3_mprintf(
150-
"CREATE TABLE IF NOT EXISTS \"%s\" (master_id INTEGER NOT NULL, key "
151-
"TEXT NOT NULL, ord INTEGER DEFAULT 0, value ANY) STRICT;",
152-
TBL_SCHEMA_PROPS);
153-
rc = sqlite3_exec(db, zSql, 0, 0, 0);
154-
sqlite3_free(zSql);
155-
156-
if (rc != SQLITE_OK) {
157-
sqlite3_exec(db, "ROLLBACK;", 0, 0, 0);
158-
return rc;
159-
}
160-
161-
zSql = sqlite3_mprintf(
162-
"CREATE UNIQUE INDEX IF NOT EXISTS __crsql_master_prop_id_index "
163-
"ON \"%s\" (master_id, key, ord);",
164-
TBL_SCHEMA_PROPS);
165-
rc = sqlite3_exec(db, zSql, 0, 0, 0);
166-
sqlite3_free(zSql);
167-
168-
if (rc != SQLITE_OK) {
169-
sqlite3_exec(db, "ROLLBACK;", 0, 0, 0);
170-
return rc;
171-
}
172-
173136
sqlite3_exec(db, "RELEASE crsql_create_schema_table;", 0, 0, 0);
174137

175138
return rc;

0 commit comments

Comments
 (0)