aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstore/ca-specific-schema.sql5
-rw-r--r--src/libstore/local-store.cc13
2 files changed, 17 insertions, 1 deletions
diff --git a/src/libstore/ca-specific-schema.sql b/src/libstore/ca-specific-schema.sql
index 08af0cc1f..64cc97fde 100644
--- a/src/libstore/ca-specific-schema.sql
+++ b/src/libstore/ca-specific-schema.sql
@@ -19,3 +19,8 @@ create table if not exists RealisationsRefs (
foreign key (referrer) references Realisations(id) on delete cascade,
foreign key (realisationReference) references Realisations(id) on delete restrict
);
+
+-- used by QueryRealisationReferences
+create index if not exists IndexRealisationsRefs on RealisationsRefs(referrer);
+-- used by cascade deletion when ValidPaths is deleted
+create index if not exists IndexRealisationsRefsOnOutputPath on Realisations(outputPath);
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index eecd407f5..fcddd1f8e 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -79,7 +79,7 @@ int getSchema(Path schemaPath)
void migrateCASchema(SQLite& db, Path schemaPath, AutoCloseFD& lockFd)
{
- const int nixCASchemaVersion = 2;
+ const int nixCASchemaVersion = 3;
int curCASchema = getSchema(schemaPath);
if (curCASchema != nixCASchemaVersion) {
if (curCASchema > nixCASchemaVersion) {
@@ -130,6 +130,17 @@ void migrateCASchema(SQLite& db, Path schemaPath, AutoCloseFD& lockFd)
txn.commit();
}
+ if (curCASchema < 3) {
+ SQLiteTxn txn(db);
+ // Apply new indices added in this schema update.
+ db.exec(R"(
+ -- used by QueryRealisationReferences
+ create index if not exists IndexRealisationsRefs on RealisationsRefs(referrer);
+ -- used by cascade deletion when ValidPaths is deleted
+ create index if not exists IndexRealisationsRefsOnOutputPath on Realisations(outputPath);
+ )");
+ txn.commit();
+ }
writeFile(schemaPath, fmt("%d", nixCASchemaVersion));
lockFile(lockFd.get(), ltRead, true);
}