### Install Pyrseas (Development Version) Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Clones the Pyrseas repository from GitHub and installs it locally for development. ```shell git clone git://github.com/perseas/Pyrseas.git cd Pyrseas python setup.py install ``` -------------------------------- ### Install Pyrseas using PGXN Client Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Installs the Pyrseas package using the PGXN client, which fetches packages from the PGXN repository. ```Shell pgxn install pyrseas ``` -------------------------------- ### Install Pyrseas (Latest Release) Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Installs the latest stable version of Pyrseas using pip. ```shell pip install Pyrseas ``` -------------------------------- ### Install Pyrseas (Unix/Linux - Superuser) Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Installs Pyrseas system-wide on Unix-like systems using administrative privileges. ```shell sudo python setup.py install ``` -------------------------------- ### Install Pyrseas (Windows - Administrator) Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Installs Pyrseas on Windows using administrative privileges. ```shell python setup.py install ``` -------------------------------- ### Clone Pyrseas Repository Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Fetches the Pyrseas source code from the GitHub repository. ```shell git clone https://github.com/perseas/Pyrseas.git ``` -------------------------------- ### Checkout Specific Pyrseas Release Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Switches the local repository to a specific tagged release of Pyrseas. ```shell git checkout vn.n.n ``` -------------------------------- ### Install Pyrseas using Pip Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Installs the Pyrseas package using the pip package installer. This is a common method for Python package management. ```Shell sudo pip install Pyrseas ``` -------------------------------- ### Update Pyrseas from Git Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Fetches the latest changes from the master branch of the Pyrseas repository. ```shell git pull ``` -------------------------------- ### Run Pyrseas Tests with tox Source: https://github.com/perseas/pyrseas/blob/master/docs/testing.rst Command to execute the Pyrseas unit tests using tox, which handles virtual environment creation and dependency installation. ```bash tox ``` -------------------------------- ### SQL CREATE Statement Example Source: https://github.com/perseas/pyrseas/blob/master/docs/overview.rst This snippet shows a basic SQL CREATE TABLE statement, which is the type of command Pyrseas utilities can generate or process. ```sql CREATE TABLE example_table ( id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL ); ``` -------------------------------- ### YAML Database Specification Example Source: https://github.com/perseas/pyrseas/blob/master/docs/overview.rst This is an example of a YAML file format that Pyrseas tools might use to define or represent a database schema. ```yaml tables: - name: users columns: - name: id type: SERIAL primary_key: true - name: username type: VARCHAR(50) nullable: false ``` -------------------------------- ### Install Pyrseas Dependencies with Pip Source: https://github.com/perseas/pyrseas/blob/master/docs/testing.rst Commands to install various Python dependencies required for Pyrseas testing using pip, the Python package installer. ```Shell pip install psycopg ``` ```Shell pip install PyYAML ``` ```Shell pip install pytest ``` ```Shell pip install tox ``` -------------------------------- ### dbtoyaml YAML Schema Example Source: https://github.com/perseas/pyrseas/blob/master/docs/dbtoyaml.rst A sample of the YAML output format generated by dbtoyaml, illustrating schema, table, column, and constraint definitions. ```yaml schema public: owner: postgres privileges: - postgres: - all - PUBLIC: - all table t1: check_constraints: t1_c2_check: columns: - c2 expression: (c2 > 123) columns: - c1: not_null: true type: integer - c2: type: smallint - c3: default: 'false' type: boolean - c4: type: text foreign_keys: t1_c2_fkey: columns: - c2 references: columns: - c21 schema: s1 table: t2 owner: alice primary_key: t1_pkey: columns: - c1 schema s1: owner: bob privileges: - bob: - all - alice: - all table t2: columns: - c21: not_null: true type: integer - c22: type: character varying(16) owner: bob primary_key: t2_pkey: columns: - c21 privileges: - bob: - all - PUBLIC: - select - alice: - insert: grantable: true - delete: grantable: true - update: grantable: true - carol: grantor: alice privs: - insert ``` -------------------------------- ### Clone Pyrseas Repository using Git Source: https://github.com/perseas/pyrseas/blob/master/docs/devel.rst This snippet shows how to clone the Pyrseas master repository from GitHub using Git. Ensure Git is installed before executing this command. ```Bash git clone https://github.com/perseas/Pyrseas.git ``` -------------------------------- ### ForeignKey Constraint Mapping Example Source: https://github.com/perseas/pyrseas/blob/master/docs/constraint.rst Illustrates the structure of a foreign key segment as returned by the `to_map` method and expected by `ConstraintDict.from_map`. This includes columns, on_delete, on_update, and references details. ```Python { 't1_fgn_key1': { 'columns': ['c2', 'c3'], 'on_delete': 'restrict', 'on_update': 'set null', 'references': { 'columns': ['pc2', 'pc1'], 'schema': 's1', 'table': 't2' } } } ``` -------------------------------- ### Extract Pyrseas Tarball Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Extracts the contents of a gzip-compressed tar archive for Pyrseas. ```shell tar xzf Pyrseas-n.n.n.tar.gz ``` -------------------------------- ### Extract Pyrseas ZIP Archive Source: https://github.com/perseas/pyrseas/blob/master/docs/install.rst Extracts the contents of a ZIP archive for Pyrseas. ```shell unzip Pyrseas-n.n.n.zip ``` -------------------------------- ### Pyrseas ForeignServer Methods Source: https://github.com/perseas/pyrseas/blob/master/docs/foreign.rst Represents a PostgreSQL foreign server. Includes methods for getting the identifier, converting to a map, and creating the server. ```Python from pyrseas.dbobject.foreign import ForeignServer # Example usage (assuming an instance 'server' exists) # server.identifier() # server.to_map() # server.create() ``` -------------------------------- ### Augmenter Schema and Table Configuration Example Source: https://github.com/perseas/pyrseas/blob/master/docs/configitems.rst Illustrates how to define specific audit column configurations for individual tables within a schema. This allows for granular control over which augmentations are applied to which tables. ```yaml augmenter: schema public: table t1: audit_columns: default ``` -------------------------------- ### Pyrseas UserMapping Methods Source: https://github.com/perseas/pyrseas/blob/master/docs/foreign.rst Represents a mapping of a PostgreSQL user to a foreign server. Includes methods for getting the external key, identifier, and creating the mapping. ```Python from pyrseas.dbobject.foreign import UserMapping # Example usage (assuming an instance 'mapping' exists) # mapping.extern_key() # mapping.identifier() # mapping.create() ``` -------------------------------- ### Example Usage of aug_set_context Source: https://github.com/perseas/pyrseas/wiki/Augmenter-Session-Variables This SQL block demonstrates how to call the `aug_set_context` function to register application-level details into PostgreSQL session variables for auditing purposes. ```sql BEGIN PERFORM aug_set_context('example_controller', 'example_action', '10.11.12.134', 'real_name', 'app_session_id'); END; ``` -------------------------------- ### YAML Schema for Audit Examples Table Source: https://github.com/perseas/pyrseas/wiki/AuditColumns This YAML snippet defines the schema for the 'audit_examples' table, including columns for audit codes, names, and audit trail information like creation and modification timestamps and IP addresses. It also specifies the primary key and audit settings. ```YAML schema example_schema: table audit_examples: columns: - audit_code: not_null: true type: character varying(5) - audit_name: not_null: true type: character varying(40) - created_by: not_null: true type: character varying(30) - created_date_time: not_null: true type: timestamp with time zone - created_by_ip: not_null: true type: inet - modified_by: not_null: true type: character varying(30) - modified_date_time: not_null: true type: timestamp with time zone - modified_by_ip: not_null: true type: inet primary_key: audit_examples_pkey: access_method: btree columns: - audit_code triggers: audit_examples_20_audit_full: events: - insert - update level: row procedure: fcl_owner.audit_full() timing: before ``` -------------------------------- ### Augmenter Column Renaming Example Source: https://github.com/perseas/pyrseas/blob/master/docs/configitems.rst Demonstrates how to specify an alternate name for a previously defined column within the Augmenter configuration. This allows for customization of column names used in database augmentations. ```yaml augmenter: columns: modified_timestamp: name: last_update ``` -------------------------------- ### Update Database Directly with SQL from YAML Source: https://github.com/perseas/pyrseas/blob/master/docs/yamltodb.rst This example demonstrates updating the 'mymovies' database directly using SQL statements generated by yamltodb from 'moviesdb.yaml'. It pipes the output to 'psql'. ```bash yamltodb --update mymovies moviesdb.yaml ``` -------------------------------- ### Trigger for Denormalizing Denorm Examples Source: https://github.com/perseas/pyrseas/wiki/Augmenter-Denormalizations This SQL trigger is set up to execute the `denorm_examples_denormalize` function before INSERT or UPDATE operations on the `denorm_examples` table. It ensures that denormalization logic is applied to the `denorm_examples` table. ```SQL CREATE TRIGGER denorm_examples_40_denormalize BEFORE INSERT OR UPDATE ON example_schema.denorm_examples FOR EACH ROW EXECUTE PROCEDURE example_schema.denorm_examples_denormalize(); ``` -------------------------------- ### Generate SQL from YAML to Update Database Source: https://github.com/perseas/pyrseas/blob/master/docs/yamltodb.rst This example shows how to use yamltodb to generate SQL statements that update a database named 'mymovies' based on a YAML file 'moviesdb.yaml'. ```bash yamltodb mymovies moviesdb.yaml ``` -------------------------------- ### Clone Pyrseas Repository with Git Source: https://github.com/perseas/pyrseas/wiki/contribute This snippet demonstrates how to clone the Pyrseas project repository using the Git version control system. It provides two common methods for cloning: one using the git:// protocol for anonymous access and another using https:// for potentially authenticated access. ```git git clone git://github.com/perseas/Pyrseas.git ``` ```git git clone https://github.com/perseas/Pyrseas.git ``` -------------------------------- ### dbtoyaml Command Synopsis Source: https://github.com/perseas/pyrseas/blob/master/docs/dbtoyaml.rst The synopsis for the dbtoyaml command, showing its basic usage with options and the database name argument. ```bash dbtoyaml [option...] dbname ``` -------------------------------- ### dbaugment Command Line Syntax Source: https://github.com/perseas/pyrseas/wiki/Augmenter This snippet shows the proposed command-line arguments for the dbaugment tool. It takes a database name, a YAML file for extensions, and an optional configuration file. ```bash dbaugment dbname extend.yaml --config config.file ``` -------------------------------- ### Example SQL Statements for Database Schema Update Source: https://github.com/perseas/pyrseas/blob/master/docs/yamltodb.rst This is an example of SQL statements that might be generated by yamltodb to create and alter schema objects, including tables, columns, constraints, and ownership, based on a YAML specification. ```sql CREATE SCHEMA s1; ALTER SCHEMA s1 OWNER TO bob; GRANT ALL ON SCHEMA s1 TO bob; GRANT ALL ON SCHEMA s1 TO alice; CREATE TABLE t1 ( c1 integer NOT NULL, c2 smallint, c3 boolean DEFAULT false, c4 text); ALTER TABLE t1 OWNER TO alice; CREATE TABLE s1.t2 ( c21 integer NOT NULL, c22 character varying(16)); ALTER TABLE s1.t2 OWNER TO bob; GRANT ALL ON TABLE s1.t2 TO bob; GRANT SELECT ON TABLE s1.t2 TO PUBLIC; GRANT INSERT, DELETE, UPDATE ON TABLE s1.t2 TO alice WITH GRANT OPTION; GRANT INSERT ON TABLE s1.t2 TO carol; ALTER TABLE t1 ADD CONSTRAINT t1_c2_check CHECK (c2 > 123); ALTER TABLE t1 ADD CONSTRAINT t1_pkey PRIMARY KEY (c1); ALTER TABLE s1.t2 ADD CONSTRAINT t2_pkey PRIMARY KEY (c21); ALTER TABLE t1 ADD CONSTRAINT t1_c2_fkey FOREIGN KEY (c2) REFERENCES s1.t2 (c21); ``` -------------------------------- ### Get Audit IP Address Function (plpgsql) Source: https://github.com/perseas/pyrseas/wiki/AuditColumns This plpgsql function retrieves the audit IP address for the current session. It first attempts to get the IP address from a session variable 'audit_ip_address' and falls back to the client's IP address if the variable is not set. ```plpgsql CREATE OR REPLACE FUNCTION example_schema.get_audit_ip_address() RETURNS inet AS $BODY$ BEGIN RETURN COALESCE(get_session_variable('audit_ip_address', NULL)::inet, inet_client_addr()); END; $BODY$ LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER COST 100; ALTER FUNCTION example_schema.get_audit_ip_address() SET search_path=example_schema, pg_temp; REVOKE EXECUTE ON FUNCTION example_schema.get_audit_ip_address() FROM public; ``` -------------------------------- ### Configure PostgreSQL Password File Source: https://github.com/perseas/pyrseas/blob/master/docs/testing.rst Shows the creation of a PostgreSQL password file, essential for secure connections. ```bash # Linux example: # ~/.pgpass # Windows example: # %APPDATA%\postgresql\pgpass.conf ``` -------------------------------- ### Create PostgreSQL User and Tablespaces Source: https://github.com/perseas/pyrseas/blob/master/docs/testing.rst This snippet demonstrates how to create a PostgreSQL user with necessary privileges and define tablespaces for the Pyrseas project. ```sql CREATE TABLESPACE ts1 LOCATION ''; CREATE TABLESPACE ts2 LOCATION ''; ``` -------------------------------- ### Pyrseas Conversion Class Methods Source: https://github.com/perseas/pyrseas/blob/master/docs/conversion.rst Demonstrates the to_map and create methods of the Pyrseas Conversion class, used for representing and creating PostgreSQL character set encoding conversions. ```Python from pyrseas.dbobject.conversion import Conversion # Example usage (assuming 'conversion_obj' is an instance of Conversion) # conversion_map = conversion_obj.to_map() # conversion_obj.create() ``` -------------------------------- ### Print Version Information Source: https://github.com/perseas/pyrseas/blob/master/docs/cmdargs.rst Prints the program's name and version identifier and then exits. ```bash pyrseas --version ``` -------------------------------- ### Clone Pyrseas Repository Source: https://github.com/perseas/pyrseas/blob/master/docs/testing.rst Command to clone the Pyrseas project repository from GitHub using Git. ```Shell git clone git://github.com/perseas/Pyrseas.git ``` -------------------------------- ### Define Copied Column in YAML Schema Source: https://github.com/perseas/pyrseas/wiki/Augmenter-Denormalizations An example YAML schema defining a table 'denorm_examples' with a column 'parent_other_column' that is copied from 'parent_table.other_column' via a foreign key 'child_parent_fk'. ```yaml schema example_schema: table denorm_examples: columns: - child_id: default: nextval('example_schema.example_seq'::regclass) not_null: true type: integer - parent_id: not_null: true type: integer - parent_other_column: not_null: true type: character varying(20) copied_from: foreign_key: child_parent_fk column: other_column foreign_keys: child_parent_fk: columns: - parent_id on_delete: restrict on_update: restrict references: columns: - parent_id schema: example_schema table: parent_table indexes: child_parent_fk_i: access_method: btree columns: - parent_id primary_key: denorm_examples_pkey: access_method: btree columns: - child_id ``` -------------------------------- ### SQL ALTER Statement Example Source: https://github.com/perseas/pyrseas/blob/master/docs/overview.rst This snippet demonstrates an SQL ALTER TABLE statement, used for modifying existing table structures, a common operation handled by Pyrseas. ```sql ALTER TABLE example_table ADD COLUMN description TEXT; ``` -------------------------------- ### OperatorClass Methods (Python) Source: https://github.com/perseas/pyrseas/blob/master/docs/operclass.rst Demonstrates the usage of key methods for the OperatorClass, including retrieving external keys, identifiers, converting to a map, and creating operator classes. ```Python from pyrseas.dbobject.operclass import OperatorClass # Example usage (assuming an OperatorClass instance 'opc' exists) # extern_key = opc.extern_key() # identifier = opc.identifier() # opc_map = opc.to_map() # opc.create() ``` -------------------------------- ### Show Help Information Source: https://github.com/perseas/pyrseas/blob/master/docs/cmdargs.rst Displays help information about the program's command-line arguments and then exits. ```bash pyrseas -h pyrseas --help ``` -------------------------------- ### Get PostgreSQL Session Variable Source: https://github.com/perseas/pyrseas/wiki/Augmenter-Session-Variables This PL/pgSQL function retrieves the value of a PostgreSQL session variable prefixed with 'augmenter.'. It is used to access stored custom session variables. ```sql CREATE OR REPLACE FUNCTION aug_get_session_variable(var_name character varying) RETURNS character varying AS $BODY$ BEGIN RETURN pg_catalog.current_setting('augmenter.' || var_name); END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; ``` -------------------------------- ### Pyrseas: INSTEAD OF Triggers and REVOKE/GRANT Commands Source: https://github.com/perseas/pyrseas/blob/master/Changelog.rst Adds support for `INSTEAD OF` triggers on views and eliminates the generation of spurious `REVOKE`/`GRANT` commands by `yamltodb`. Also removes `setuptools` from `setup.py`'s `install_requires`. ```SQL -- Example of PostgreSQL INSTEAD OF trigger syntax -- CREATE TRIGGER my_view_trigger -- INSTEAD OF INSERT ON my_view -- FOR EACH ROW EXECUTE FUNCTION my_view_trigger_func(); ``` -------------------------------- ### Calculate Denormalization in YAML Source: https://github.com/perseas/pyrseas/wiki/Augmenter-Denormalizations Defines a calculated denormalization for the 'total_value' column in the 'order_items' table, multiplying 'item_price' by 'qty'. This example shows how to define such a calculation directly within the schema definition. ```yaml schema example_schema: table order_items: columns: - order_id: not_null: true type: integer - item_no: not_null: true type: integer - item_price: not_null: true type: numeric(10,2) - qty: not_null: true type: integer - total_value: type: numeric(10,2) calculated_from: {item_price} * {qty} primary_key: order_items_pkey: access_method: btree columns: - order_id - item_no ``` -------------------------------- ### Pyrseas dbaugment Tool Prototype Source: https://github.com/perseas/pyrseas/wiki/Augmenter A prototype man page and a small proof-of-concept script for the dbaugment tool are being developed. The tool's output can be directed to standard output for piping or consumed internally by yamltodb. ```Python dbaugment.py ``` -------------------------------- ### Pyrseas ConversionDict Class Method Source: https://github.com/perseas/pyrseas/blob/master/docs/conversion.rst Illustrates the from_map method of the Pyrseas ConversionDict class, used for creating a collection of conversions from a map representation. ```Python from pyrseas.dbobject.conversion import ConversionDict # Example usage (assuming 'conversion_dict_data' is a dictionary) # conversion_dict = ConversionDict.from_map(conversion_dict_data) ``` -------------------------------- ### Get PostgreSQL Session Variable with Default Source: https://github.com/perseas/pyrseas/wiki/Augmenter-Session-Variables This PL/pgSQL function retrieves the value of a PostgreSQL session variable prefixed with 'augmenter.'. If the variable is not set, it returns a specified default value. ```sql CREATE OR REPLACE FUNCTION aug_get_session_variable(var_name character varying, default_value character varying) RETURNS character varying AS $BODY$ BEGIN RETURN pg_catalog.current_setting('augmenter.' || var_name); EXCEPTION WHEN undefined_object THEN RETURN default_value; END; $BODY$ LANGUAGE plpgsql VOLATILE COST 100; ``` -------------------------------- ### Specify Repository Path Source: https://github.com/perseas/pyrseas/blob/master/docs/cmdargs.rst Specifies the path to a directory for metadata and static data files, or for an additional configuration file. Defaults to the current working directory if not specified. ```bash pyrseas -r pyrseas --repository ``` -------------------------------- ### Create or Upgrade Database from YAML Specification using yamltodb Source: https://github.com/perseas/pyrseas/blob/master/docs/overview.rst The `yamltodb` utility takes a YAML specification file as input and generates a script of SQL CREATE or ALTER statements. This script can be used to create or upgrade a test or production database to match the input specification. ```bash yamltodb < specification.yaml ``` -------------------------------- ### Pyrseas Index Class Methods Source: https://github.com/perseas/pyrseas/blob/master/docs/indexes.rst Demonstrates methods for the Index class in Pyrseas, including key expressions, mapping to a dictionary, and operations for creating, altering, and dropping indexes. ```Python from pyrseas.dbobject.index import Index # Example usage (conceptual): # index_obj = Index(schema='public', table='users', name='idx_email') # key_expr = index_obj.key_expressions() # index_map = index_obj.to_map() # index_obj.create() # index_obj.alter() # index_obj.drop() ``` -------------------------------- ### PL/pgSQL Function to Get Audit IP Address Source: https://github.com/perseas/pyrseas/wiki/AuditColumns A simple PL/pgSQL function that returns the IP address of the current client connected to the database. This is used in audit logging to track the origin of database operations. ```PL/pgSQL language: plpgsql returns: inet source: "\nBEGIN RETURN inet_client_addr(); END;" ``` -------------------------------- ### Extract to Directory for Version Control Source: https://github.com/perseas/pyrseas/blob/master/docs/dbtoyaml.rst Extracts database objects into a directory structure suitable for version control. The '-m' option enables multiple file output, and the output is placed in the 'movies/dbspec' directory. ```bash dbtoyaml moviesdb -m movies/dbspec ``` -------------------------------- ### YAML Specification for Database Augmentation Source: https://github.com/perseas/pyrseas/blob/master/docs/dbaugment.rst Defines database augmentations, including adding audit columns to tables. This example specifies a 'modified_only' audit column for the 'public.film' table and renames the default 'modified_timestamp' column to 'updated'. ```yaml augmenter: columns: modified_timestamp: name: updated schema public: table film: audit_columns: modified_only ``` -------------------------------- ### Generate and Save SQL in a Single Transaction Source: https://github.com/perseas/pyrseas/blob/master/docs/yamltodb.rst This example shows how to generate SQL statements from 'dbtoyaml' output, process them with yamltodb in a single transaction ('-1'), specify the target database 'mymovies', and save the output to 'mymovies.sql'. ```bash dbtoyaml devmovies | yamltodb -1 mymovies -o mymovies.sql ``` -------------------------------- ### Run Pyrseas Tests with Pytest Source: https://github.com/perseas/pyrseas/blob/master/docs/testing.rst Commands to execute Pyrseas unit tests using the pytest framework. This includes running all tests for a specific module, or running a single test case with a keyword filter. ```Shell pytest-3 tests/dbobject/test_table.py ``` ```Shell pytest-3 tests/dbobject/test_trigger.py -k test_create_trigger ``` ```Shell pytest-3 tests/functional ``` -------------------------------- ### PL/pgSQL Function to Get Audit User Source: https://github.com/perseas/pyrseas/wiki/AuditColumns Defines a PL/pgSQL function that retrieves the current audit user, falling back to the session user if no specific audit user is set. This function is crucial for audit trail logging. ```SQL CREATE OR REPLACE FUNCTION example_schema.get_audit_user() RETURNS character varying AS $BODY$ BEGIN RETURN COALESCE(get_session_variable('audit_user', NULL), SESSION_USER); END; $BODY$ LANGUAGE 'plpgsql' VOLATILE SECURITY DEFINER COST 100; ALTER FUNCTION example_schema.get_audit_user() SET search_path=example_schema, pg_temp; REVOKE EXECUTE ON FUNCTION example_schema.get_audit_user() FROM public; ``` -------------------------------- ### OperatorClassDict Loading (Python) Source: https://github.com/perseas/pyrseas/blob/master/docs/operclass.rst Shows how to load operator class data from a map into an OperatorClassDict instance. ```Python from pyrseas.dbobject.operclass import OperatorClassDict # Example usage (assuming a dictionary 'data_map' exists) # opc_dict = OperatorClassDict.from_map(data_map) ``` -------------------------------- ### Define Table Alias for Trigger Naming Source: https://github.com/perseas/pyrseas/wiki/Augmenter-Configuration This YAML example shows how to define an alias for a table to be used in generated trigger names. Instead of using the full table name, the alias simplifies the trigger name, especially for tables with long names. ```yaml schema: example table example_customers: alias: cst audited: true ``` -------------------------------- ### Generate YAML Specification from Database using dbtoyaml Source: https://github.com/perseas/pyrseas/blob/master/docs/overview.rst The `dbtoyaml` utility generates a YAML specification file from a PostgreSQL database. It can be used with the `--multiple-files` option to break down the specification into files corresponding to individual database objects, facilitating version control by allowing VCS diffs to highlight changes. ```bash dbtoyaml --multiple-files ``` -------------------------------- ### Denormalize Parent Column in Denorm Examples Source: https://github.com/perseas/pyrseas/wiki/Augmenter-Denormalizations This PostgreSQL function handles the denormalization of a parent table's column into a child table. It triggers on INSERT or UPDATE operations in the child table, copying data from the parent table based on a foreign key relationship. It ensures that changes in the parent table are reflected in the child table's denormalized column. ```plpgsql CREATE OR REPLACE FUNCTION example_schema.denorm_examples_denormalize() RETURNS trigger AS $BODY$ BEGIN -- Denormalize parent_other_column via child_parent_fk IF TG_OP = 'INSERT' THEN SELECT other_column INTO NEW.parent_other_column FROM example_schema.parent_table WHERE parent_id = NEW.parent_id; ELSIF TG_OP = 'UPDATE' AND ( NEW.parent_id IS DISTINCT FROM OLD.parent_id OR NEW.parent_other_column IS NULL) THEN SELECT other_column INTO NEW.parent_other_column FROM example_schema.parent_table WHERE parent_id = NEW.parent_id; ELSE NEW.parent_other_column = OLD.parent_other_column; END IF; RETURN NEW; END; $BODY$ LANGUAGE plpgsql; ``` -------------------------------- ### Pyrseas: Initial release features Source: https://github.com/perseas/pyrseas/blob/master/Changelog.rst Details the features supported in the initial release of Pyrseas, including dbtoyaml and yamltodb support for schemas, tables, sequences, constraints, and indexes. ```Python # dbtoyaml and yamltodb support PostgreSQL schemas, tables, # sequences, check constraints, primary keys, foreign keys, unique # constraints and indexes. ``` -------------------------------- ### AugmentDatabase.from_augmap Method (Python) Source: https://github.com/perseas/pyrseas/blob/master/docs/augmentdb.rst Initializes an AugmentDatabase instance from an augmentation map. This method allows for the configuration of schemas and augmenters to be loaded from a provided 'aug_map'. ```Python def from_augmap(cls, aug_map): """Initializes an AugmentDatabase from an augmentation map.""" pass ``` -------------------------------- ### Specify Configuration File Source: https://github.com/perseas/pyrseas/blob/master/docs/cmdargs.rst Specifies an additional configuration file to be read and merged with existing configuration. The default behavior relies on other configuration sources. ```bash pyrseas -c pyrseas --config ``` -------------------------------- ### Language Class Methods (Python) Source: https://github.com/perseas/pyrseas/blob/master/docs/language.rst Demonstrates methods for the Language class, including converting to a map, dropping the language, and creating the language. These methods are part of the pyrseas.dbobject.language module. ```Python from pyrseas.dbobject.language import Language # Example usage (assuming language object is instantiated) # language.to_map() # language.drop() # language.create() ``` -------------------------------- ### Pyrseas: New Utility 'dbaugment' and TTM-inspired Interface Source: https://github.com/perseas/pyrseas/blob/master/Changelog.rst Introduces a new experimental utility, `dbaugment`, for consistently adding objects to an existent database, focusing on adding audit columns to tables. Also presents a new interface to PostgreSQL inspired by *The Third Manifesto*. ```Python # Conceptual Python code for dbaugment utility # def add_audit_columns(table_name): # # ... logic to add audit columns # Conceptual representation of TTM-inspired interface (Python) # class TtmRelation: # def __init__(self, name): # self.name = name # # ... methods for relational operations ``` -------------------------------- ### Load Text Search Configuration Dictionary from Map in Pyrseas Source: https://github.com/perseas/pyrseas/blob/master/docs/textsearch.rst Demonstrates loading a collection of text search configurations from a map (dictionary) into a TSConfigurationDict object. The from_map method facilitates this data loading. ```Python from pyrseas.dbobject.textsearch import TSConfigurationDict # Example usage (assuming 'config_map_data' is a dictionary representing configurations) # config_dict = TSConfigurationDict.from_map(config_map_data) ``` -------------------------------- ### Pyrseas IndexDict Class Method Source: https://github.com/perseas/pyrseas/blob/master/docs/indexes.rst Illustrates the from_map method for the IndexDict class in Pyrseas, used to create an IndexDict object from a dictionary representation. ```Python from pyrseas.dbobject.index import IndexDict # Example usage (conceptual): # index_data = { # 'index1': {'schema': 'public', 'table': 'users', 'name': 'idx_email'}, # 'index2': {'schema': 'public', 'table': 'products', 'name': 'idx_sku'} # } # index_dict_obj = IndexDict.from_map(index_data) ``` -------------------------------- ### Force Password Prompt Source: https://github.com/perseas/pyrseas/blob/master/docs/cmdargs.rst Forces the program to prompt for a password before connecting to a database. Without this, libpq defaults (password file or PGPASSWORD) are used if authentication is required. ```bash pyrseas -W pyrseas --password ``` -------------------------------- ### Extract Database to YAML File Source: https://github.com/perseas/pyrseas/blob/master/docs/dbtoyaml.rst Extracts a database schema into a single YAML file. The output is directed to standard output, which can be redirected to a file. ```bash dbtoyaml moviesdb > moviesdb.yaml ``` -------------------------------- ### Pyrseas: File Output and Configuration Management Source: https://github.com/perseas/pyrseas/blob/master/Changelog.rst Introduces changes to how Pyrseas handles file output, including using relative paths for `--multiple-files` and ensuring UTF-8 encoding for file output. Configuration files are now managed under the `pyrseas` directory. ```Python # Conceptual Python code for file path handling and encoding # import os # output_path = os.path.join(base_dir, "..", "output_file.yaml") # with open(output_path, 'w', encoding='utf-8') as f: # f.write(data) ``` -------------------------------- ### Pyrseas Augmenter Round-tripping Source: https://github.com/perseas/pyrseas/wiki/Augmenter The Augmenter tool will support round-tripping by processing dbtoyaml output files, converting generated business logic back to declarations, or using the dbtoyaml output as its own input, only generating new or changed business logic. ```Python # Example of processing dbtoyaml output dbtoyaml_output = "..." augmenter.process(dbtoyaml_output) # Example of using dbtoyaml output as input dbtoyaml_input = "..." augmenter.process(dbtoyaml_input, use_as_input=True) ``` -------------------------------- ### Configure Datacopy Schema and Tables Source: https://github.com/perseas/pyrseas/blob/master/docs/configitems.rst Specifies which tables to export from or import to the database. It includes schema names followed by lists of table names. ```YAML datacopy: schema public: - t1 - t2 schema s1: - t3 ``` -------------------------------- ### Grant Permissions on Tablespace Directory (Windows) Source: https://github.com/perseas/pyrseas/blob/master/docs/testing.rst Windows command to grant full control permissions to the 'postgres' user on a specified directory, often needed for tablespaces. ```powershell cacls /E /G postgres:F ``` -------------------------------- ### Pyrseas: Added files for release via PGXN Source: https://github.com/perseas/pyrseas/blob/master/Changelog.rst Includes necessary files and configurations for releasing the Pyrseas project via the PostgreSQL Extension Network (PGXN). ```Python # Added files for release via PGXN. ```