Skip to content

Commit

Permalink
Add loadSchema service
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Feb 15, 2024
1 parent 3ebcd95 commit f6a8863
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions NixSupport/nixosModules/services/loadSchema.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ self, config, pkgs, ihp, ... }:
let cfg = config.services.ihp;
in
{
systemd.services.loadSchema = {
serviceConfig = {
Type = "oneshot";
};
script = ''
DB_URL=''${DATABASE_URL:-''${DEFAULT_DATABASE_URL}}
psql "$DB_URL" < ${self.packages.x86_64-linux.ihp-schema}/IHPSchema.sql
psql "$DB_URL" < ${self.packages.x86_64-linux.schema}/Schema.sql
'';
environment = {
DEFAULT_DATABASE_URL = cfg.databaseUrl;
};
};
}
11 changes: 11 additions & 0 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ ihpFlake:
cp ${ihp}/lib/IHP/IHPSchema.sql $out/
'';
};


schema = pkgs.stdenv.mkDerivation {
name = "schema";
src = cfg.projectPath;
phases = [ "unpackPhase" "installPhase" ];
installPhase = ''
mkdir $out
cp Application/Schema.sql $out/
'';
};
};

devenv.shells.default = lib.mkIf cfg.enable {
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
services_app = ./NixSupport/nixosModules/services/app.nix;
services_worker = ./NixSupport/nixosModules/services/worker.nix;
services_migrate = ./NixSupport/nixosModules/services/migrate.nix;
services_loadSchema = ./NixSupport/nixosModules/services/loadSchema.nix;
options = ./NixSupport/nixosModules/options.nix;
binaryCache = ./NixSupport/nixosModules/binaryCache.nix;
};
Expand Down

0 comments on commit f6a8863

Please sign in to comment.