Edit

PostgreSQL database definition

This article provides a breakdown of the definition structure for PostgreSQL database items.

Supported formats

PostgreSQL database items support the pgschema format. If you don't specify a format, pgschema is used.

A pgschema definition describes the schema of the database: tables, views, materialized views, functions, stored procedures, aggregates, user-defined types, domains, sequences, and privileges. It doesn't include the data stored in tables, credentials or other secrets, connection details, or the item's sensitivity label.

Definition parts

This table lists the PostgreSQL database definition parts.

Definition part path Type Required Description
definition.pgschema ZIP archive true The database schema, packaged as a ZIP archive of SQL files. A definition contains exactly one definition.pgschema part. See definition.pgschema archive.
.platform PlatformDetails (JSON) false Describes common details of the item, such as its display name and description. See Platform file.

Both parts use the InlineBase64 payload type.

definition.pgschema archive

The Base64-decoded payload of the definition.pgschema part is a ZIP archive with the following contents.

Path Type Required Description
manifest.json Manifest (JSON) true Identifies the definition format and version. See Manifest.
main.sql SQL true The entry script, which includes the other SQL files of the definition. See main.sql.
types/*.sql SQL false User-defined type declarations.
domains/*.sql SQL false Domain declarations.
sequences/*.sql SQL false Sequence declarations.
functions/*.sql SQL false Function declarations and source.
procedures/*.sql SQL false Stored procedure declarations and source.
aggregates/*.sql SQL false Aggregate declarations.
tables/*.sql SQL false Table declarations, with their constraints, indexes, and triggers.
views/*.sql SQL false View declarations.
materialized_views/*.sql SQL false Materialized view declarations, with their indexes and comments.
privileges/*.sql SQL false Object and column GRANT and REVOKE statements.
default_privileges/*.sql SQL false Schema-scoped default GRANT and REVOKE statements.

The folders in this table are the layout that's returned when you get a definition, with one file per database object. When you create a database with a definition or update a definition, you can use other relative paths for SQL files, as long as main.sql includes them.

The archive must follow these rules:

  • Paths are relative and use forward slashes (/). A path can't start with /, contain :, or contain empty, ., or .. segments.
  • The archive can't contain directory entries. For example, if you create the archive with the zip command-line tool, use the -D option.
  • Every file except manifest.json has the .sql extension. SQL files other than main.sql can't be empty.
  • Files are UTF-8 encoded text.
  • Paths are unique, regardless of case.

Manifest

manifest.json identifies the format and version of the definition. It contains exactly the following properties, and no others.

Property Type Required Description
$schema String true The manifest JSON schema. Must be https://developer.microsoft.com/json-schemas/fabric/item/postgreSQLDatabase/definition/manifest/1.0.0/schema.json.
format String true The definition format. Must be pgschema.
version String true The definition format version. Must be 1.0.0.

Manifest example

{
  "$schema": "https://developer.microsoft.com/json-schemas/fabric/item/postgreSQLDatabase/definition/manifest/1.0.0/schema.json",
  "format": "pgschema",
  "version": "1.0.0"
}

main.sql

main.sql is the entry script of the definition. It can contain SQL statements, and it includes other SQL files from the archive with \i directives, one directive per line:

  • \i tables/orders.sql includes a single file.
  • \i tables/ includes every .sql file in the folder and its subfolders, in alphabetical order.

Included files can also include other files. Include paths are relative to the file that contains the directive, and can't point outside the archive. Circular includes aren't allowed.

Include files in dependency order. For example, include a table before the views that reference it. When you get a definition, the returned main.sql includes each object file in dependency order.

main.sql example

CREATE SCHEMA IF NOT EXISTS sales;
\i tables/orders.sql
\i views/order_totals.sql

Platform file

The optional .platform part contains the item's metadata, and isn't part of the definition.pgschema archive. For more information, see Platform file.

The display name of a PostgreSQL database can't be changed. When you update a definition with updateMetadata=true, you can change the description in .platform. A .platform part with a different display name is rejected with the PostgreSQLDatabaseDisplayNameCannotBeChanged error.

Platform file example

{
  "$schema": "https://developer.microsoft.com/json-schemas/fabric/gitIntegration/platformProperties/2.0.0/schema.json",
  "metadata": {
    "type": "PostgreSQLDatabase",
    "displayName": "SalesOperations",
    "description": "Order schema and customer totals for sales operations."
  },
  "config": {
    "version": "2.0",
    "logicalId": "6f2c4590-6138-4a21-8c7d-501cd3077e9b"
  }
}

Definition example

This example defines a sales schema with an orders table and an order_totals view. Besides manifest.json and main.sql from the earlier examples, the archive contains the following files.

tables/orders.sql:

CREATE TABLE sales.orders (
    order_id bigint PRIMARY KEY,
    customer_id bigint NOT NULL,
    total_amount numeric(12, 2) NOT NULL CHECK (total_amount >= 0)
);

views/order_totals.sql:

CREATE VIEW sales.order_totals AS
SELECT customer_id, sum(total_amount) AS total_amount
FROM sales.orders
GROUP BY customer_id;

The definition contains the Base64-encoded archive in the definition.pgschema part, and the Base64-encoded platform file in the .platform part.

{
  "format": "pgschema",
  "parts": [
    {
      "path": "definition.pgschema",
      "payload": "UEsDBBQAAAAAAAAAISgN3c61pgAAAKYAAAANAAAAbWFuaWZlc3QuanNvbnsiJHNjaGVtYSI6Imh0dHBzOi8vZGV2ZWxvcGVyLm1pY3Jvc29mdC5jb20vanNvbi1zY2hlbWFzL2ZhYnJpYy9pdGVtL3Bvc3RncmVTUUxEYXRhYmFzZS9kZWZpbml0aW9uL21hbmlmZXN0LzEuMC4wL3NjaGVtYS5qc29uIiwiZm9ybWF0IjoicGdzY2hlbWEiLCJ2ZXJzaW9uIjoiMS4wLjAifQpQSwMEFAAAAAAAAAAhKABjSJNSAAAAUgAAAAgAAABtYWluLnNxbENSRUFURSBTQ0hFTUEgSUYgTk9UIEVYSVNUUyBzYWxlczsKXGkgdGFibGVzL29yZGVycy5zcWwKXGkgdmlld3Mvb3JkZXJfdG90YWxzLnNxbApQSwMEFAAAAAAAAAAhKJvoLSGkAAAApAAAABEAAAB0YWJsZXMvb3JkZXJzLnNxbENSRUFURSBUQUJMRSBzYWxlcy5vcmRlcnMgKAogICAgb3JkZXJfaWQgYmlnaW50IFBSSU1BUlkgS0VZLAogICAgY3VzdG9tZXJfaWQgYmlnaW50IE5PVCBOVUxMLAogICAgdG90YWxfYW1vdW50IG51bWVyaWMoMTIsIDIpIE5PVCBOVUxMIENIRUNLICh0b3RhbF9hbW91bnQgPj0gMCkKKTsKUEsDBBQAAAAAAAAAISijct55gAAAAIAAAAAWAAAAdmlld3Mvb3JkZXJfdG90YWxzLnNxbENSRUFURSBWSUVXIHNhbGVzLm9yZGVyX3RvdGFscyBBUwpTRUxFQ1QgY3VzdG9tZXJfaWQsIHN1bSh0b3RhbF9hbW91bnQpIEFTIHRvdGFsX2Ftb3VudApGUk9NIHNhbGVzLm9yZGVycwpHUk9VUCBCWSBjdXN0b21lcl9pZDsKUEsBAhQAFAAAAAAAAAAhKA3dzrWmAAAApgAAAA0AAAAAAAAAAAAAAAAAAAAAAG1hbmlmZXN0Lmpzb25QSwECFAAUAAAAAAAAACEoAGNIk1IAAABSAAAACAAAAAAAAAAAAAAAAADRAAAAbWFpbi5zcWxQSwECFAAUAAAAAAAAACEom+gtIaQAAACkAAAAEQAAAAAAAAAAAAAAAABJAQAAdGFibGVzL29yZGVycy5zcWxQSwECFAAUAAAAAAAAACEoo3LeeYAAAACAAAAAFgAAAAAAAAAAAAAAAAAcAgAAdmlld3Mvb3JkZXJfdG90YWxzLnNxbFBLBQYAAAAABAAEAPQAAADQAgAAAAA=",
      "payloadType": "InlineBase64"
    },
    {
      "path": ".platform",
      "payload": "eyIkc2NoZW1hIjoiaHR0cHM6Ly9kZXZlbG9wZXIubWljcm9zb2Z0LmNvbS9qc29uLXNjaGVtYXMvZmFicmljL2dpdEludGVncmF0aW9uL3BsYXRmb3JtUHJvcGVydGllcy8yLjAuMC9zY2hlbWEuanNvbiIsIm1ldGFkYXRhIjp7InR5cGUiOiJQb3N0Z3JlU1FMRGF0YWJhc2UiLCJkaXNwbGF5TmFtZSI6IlNhbGVzT3BlcmF0aW9ucyIsImRlc2NyaXB0aW9uIjoiT3JkZXIgc2NoZW1hIGFuZCBjdXN0b21lciB0b3RhbHMgZm9yIHNhbGVzIG9wZXJhdGlvbnMuIn0sImNvbmZpZyI6eyJ2ZXJzaW9uIjoiMi4wIiwibG9naWNhbElkIjoiNmYyYzQ1OTAtNjEzOC00YTIxLThjN2QtNTAxY2QzMDc3ZTliIn19Cg==",
      "payloadType": "InlineBase64"
    }
  ]
}