@phase2 @acms @analyzer @postgresql_analyzer @coverage_boost
Feature: PostgreSQLAnalyzer coverage boost
  Additional scenarios targeting uncovered branches in
  src/cleveragents/domain/models/acms/postgresql_analyzer.py.

  Background:
    Given a fresh PostgreSQLAnalyzer instance

  # ---- Line 135: duplicate CREATE SCHEMA is skipped ---------------------

  Scenario: Duplicate CREATE SCHEMA statements are deduplicated
    When I analyze DDL with duplicate schemas:
      """
      CREATE SCHEMA IF NOT EXISTS billing;
      CREATE SCHEMA billing;
      CREATE TABLE billing.invoices (id SERIAL PRIMARY KEY);
      """
    Then exactly 1 Schema type triple should exist
    And the result triples should contain predicate "rdfs:label" with value "billing"

  # ---- Lines 112-116: exception handler returns partial results ---------

  Scenario: Internal parse error returns partial results gracefully
    When I analyze DDL that triggers an internal parse error
    Then the partial results should be returned without raising
    And the parse error should have been logged as a warning

  # ---- Line 198: _extract_tables with tables_seen=None ------------------

  Scenario: Calling _extract_tables directly with tables_seen defaulting to None
    When I call _extract_tables directly without tables_seen on:
      """
      CREATE TABLE widgets (id SERIAL PRIMARY KEY, name TEXT);
      """
    Then the direct extraction should produce Table triples for "widgets"

  # ---- Line 285: CREATE VIEW without trailing semicolon -----------------

  Scenario: CREATE VIEW without trailing semicolon captures view definition
    When I analyze DDL with a view missing its semicolon:
      """
      CREATE VIEW recent_orders AS
      SELECT * FROM orders WHERE created_at > NOW() - INTERVAL '7 days'
      """
    Then the result triples should contain predicate "rdf:type" with uri "uko-data:View"
    And the result triples should contain predicate "uko-data:viewDefinition" present
    And the viewDefinition value should contain "SELECT"

  # ---- Lines 297-302: schema-qualified CREATE VIEW ----------------------

  Scenario: Schema-qualified CREATE VIEW emits schema and uko:contains link
    When I analyze DDL with a schema-qualified view:
      """
      CREATE VIEW reporting.monthly_sales AS
      SELECT * FROM sales WHERE month = EXTRACT(MONTH FROM NOW());
      """
    Then the result triples should contain predicate "rdf:type" with uri "uko-data:View"
    And the result triples should contain predicate "rdf:type" with uri "uko-data:Schema"
    And the result triples should contain predicate "uko:contains" linking schema "reporting" to view "monthly_sales"

  Scenario: Schema-qualified OR REPLACE view also emits schema contains link
    When I analyze DDL with a schema-qualified view:
      """
      CREATE OR REPLACE VIEW analytics.daily_stats AS
      SELECT COUNT(*) FROM events GROUP BY date;
      """
    Then the result triples should contain predicate "rdf:type" with uri "uko-data:View"
    And the result triples should contain predicate "rdf:type" with uri "uko-data:Schema"
    And the result triples should contain predicate "uko:contains" linking schema "analytics" to view "daily_stats"
