diff --git a/Directory.Build.props b/Directory.Build.props
index 03e4b6e0a..ff1e5ee05 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -26,8 +26,8 @@
https://github.com/managedcode/graphrag
https://github.com/managedcode/graphrag
Managed Code GraphRag
- 10.0.5
- 10.0.5
+ 10.0.6
+ 10.0.6
diff --git a/src/ManagedCode.GraphRag.Postgres/ApacheAge/AgeConnectionManager.cs b/src/ManagedCode.GraphRag.Postgres/ApacheAge/AgeConnectionManager.cs
index 59bb7a28b..a90b49c51 100644
--- a/src/ManagedCode.GraphRag.Postgres/ApacheAge/AgeConnectionManager.cs
+++ b/src/ManagedCode.GraphRag.Postgres/ApacheAge/AgeConnectionManager.cs
@@ -132,12 +132,38 @@ private async Task LoadAgeAsync(NpgsqlConnection connection, CancellationToken c
{
try
{
+ await using var checkCommand = connection.CreateCommand();
+ checkCommand.CommandText = "SELECT 1 FROM pg_extension WHERE extname = 'age';";
+ checkCommand.CommandTimeout = 0;
+ var result = await checkCommand.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false);
+
+ if (result is null)
+ {
+ throw new AgeException("AGE extension is not installed.");
+ }
+
await using var load = connection.CreateCommand();
load.CommandText = "LOAD 'age';";
load.CommandTimeout = 0;
await load.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false);
LogMessages.ExtensionLoaded(_logger, ConnectionString);
}
+ catch (PostgresException ex) when (ex.SqlState == "42501")
+ {
+ await using var initCommand = connection.CreateCommand();
+ initCommand.CommandText = "SELECT ag_catalog.create_graph('__age_init__'); SELECT ag_catalog.drop_graph('__age_init__', true);";
+ initCommand.CommandTimeout = 0;
+
+ try
+ {
+ await initCommand.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false);
+ }
+ catch (PostgresException)
+ {
+ }
+
+ LogMessages.ExtensionLoaded(_logger, ConnectionString);
+ }
catch (PostgresException ex)
{
LogMessages.ExtensionNotLoadedError(_logger, ConnectionString, ex.MessageText);