# Pams.Database

**Kind:** Module

**Source:** `Pams/Database/Pams.Database/PamsDatabaseSolution/../Pams.Database.sqlproj` (line 1)

**Part of:** [Pams](subsystem-pams)

.NET project in solution

`Pams.Database` is a .NET database project within the solution. It defines the database schema and produces a deployable database artifact that other Pams components can target during local development and deployment.

## Diagram

```mermaid
graph TD
  Schema[Database schema files] --> Project[Pams.Database.sqlproj]
  Project --> Build[dotnet build]
  Build --> Dacpac[Database deployment artifact]
  Dacpac --> Publish[Deployment tool]
  Publish --> Database[Target database]
```

## Usage

```ts
import { execFileSync } from "node:child_process";

const projectPath = process.env.PAMS_DATABASE_PROJECT;
const dacpacPath = process.env.PAMS_DATABASE_DACPAC;
const connectionString = process.env.PAMS_DATABASE_CONNECTION_STRING;

if (!projectPath || !dacpacPath || !connectionString) {
  throw new Error(
    "Set PAMS_DATABASE_PROJECT, PAMS_DATABASE_DACPAC, and PAMS_DATABASE_CONNECTION_STRING.",
  );
}

execFileSync("dotnet", ["build", projectPath], {
  stdio: "inherit",
});

execFileSync(
  "sqlpackage",
  [
    "/Action:Publish",
    `/SourceFile:${dacpacPath}`,
    `/TargetConnectionString:${connectionString}`,
  ],
  { stdio: "inherit" },
);
```

## AI Coding Instructions

- Treat `Pams.Database.sqlproj` as the source of truth for database schema changes; do not edit generated deployment artifacts.
- Add schema objects through the database project so they are included in the build output.
- Keep application queries and migrations compatible with the schema defined by this project.
- Do not treat this project as a TypeScript or .NET runtime library; build and deploy it through database project tooling.
