text:
-- phpMyAdmin SQL Dump
-- version 3.3.9
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Sep 14, 2014 at 04:26 PM
-- Server version: 5.5.8
-- PHP Version: 5.3.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `cafe`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_app_config`
--

CREATE TABLE IF NOT EXISTS `ospos_app_config` (
  `key` varchar(255) NOT NULL,
  `value` varchar(255) NOT NULL,
  PRIMARY KEY (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_app_config`
--

INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('address', '123 Nowhere street'),
('company', 'Open Source Point of Sale'),
('default_tax_rate', '8'),
('email', 'admin@pappastech.com'),
('fax', ''),
('phone', '555-555-5555'),
('return_policy', 'Test'),
('timezone', 'America/New_York'),
('website', '');

-- --------------------------------------------------------

--
-- Table structure for table `ospos_customers`
--

CREATE TABLE IF NOT EXISTS `ospos_customers` (
  `person_id` int(10) NOT NULL,
  `account_number` varchar(255) DEFAULT NULL,
  `taxable` int(1) NOT NULL DEFAULT '1',
  `deleted` int(1) NOT NULL DEFAULT '0',
  UNIQUE KEY `account_number` (`account_number`),
  KEY `person_id` (`person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_customers`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_employees`
--

CREATE TABLE IF NOT EXISTS `ospos_employees` (
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `person_id` int(10) NOT NULL,
  `deleted` int(1) NOT NULL DEFAULT '0',
  UNIQUE KEY `username` (`username`),
  KEY `person_id` (`person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_employees`
--

INSERT INTO `ospos_employees` (`username`, `password`, `person_id`, `deleted`) VALUES
('admin', '439a6de57d475c1a0ba9bcb1c39f0af6', 1, 0);

-- --------------------------------------------------------

--
-- Table structure for table `ospos_giftcards`
--

CREATE TABLE IF NOT EXISTS `ospos_giftcards` (
  `giftcard_id` int(11) NOT NULL AUTO_INCREMENT,
  `giftcard_number` varchar(25) COLLATE utf8_unicode_ci NOT NULL,
  `value` double(15,2) NOT NULL,
  `deleted` int(1) NOT NULL DEFAULT '0',
  `person_id` int(11) NOT NULL,
  PRIMARY KEY (`giftcard_id`),
  UNIQUE KEY `giftcard_number` (`giftcard_number`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=48 ;

--
-- Dumping data for table `ospos_giftcards`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_inventory`
--

CREATE TABLE IF NOT EXISTS `ospos_inventory` (
  `trans_id` int(11) NOT NULL AUTO_INCREMENT,
  `trans_items` int(11) NOT NULL DEFAULT '0',
  `trans_user` int(11) NOT NULL DEFAULT '0',
  `trans_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `trans_comment` text NOT NULL,
  `trans_senior` varchar(40) NOT NULL,
  `trans_take_type` varchar(40) NOT NULL,
  `trans_inventory` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`trans_id`),
  KEY `ospos_inventory_ibfk_1` (`trans_items`),
  KEY `ospos_inventory_ibfk_2` (`trans_user`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `ospos_inventory`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_items`
--

CREATE TABLE IF NOT EXISTS `ospos_items` (
  `name` varchar(255) NOT NULL,
  `category` varchar(255) NOT NULL,
  `supplier_id` int(11) DEFAULT NULL,
  `item_number` varchar(255) DEFAULT NULL,
  `description` varchar(255) NOT NULL,
  `cost_price` double(15,2) NOT NULL,
  `unit_price` double(15,2) NOT NULL,
  `quantity` double(15,2) NOT NULL DEFAULT '0.00',
  `reorder_level` double(15,2) NOT NULL DEFAULT '0.00',
  `location` varchar(255) NOT NULL,
  `item_id` int(10) NOT NULL AUTO_INCREMENT,
  `allow_alt_description` tinyint(1) NOT NULL,
  `is_serialized` tinyint(1) NOT NULL,
  `deleted` int(1) NOT NULL DEFAULT '0',
  `custom1` varchar(25) NOT NULL,
  `custom2` varchar(25) NOT NULL,
  `custom3` varchar(25) NOT NULL,
  `custom4` varchar(25) NOT NULL,
  `custom5` varchar(25) NOT NULL,
  `custom6` varchar(25) NOT NULL,
  `custom7` varchar(25) NOT NULL,
  `custom8` varchar(25) NOT NULL,
  `custom9` varchar(25) NOT NULL,
  `custom10` varchar(25) NOT NULL,
  PRIMARY KEY (`item_id`),
  UNIQUE KEY `item_number` (`item_number`),
  KEY `ospos_items_ibfk_1` (`supplier_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `ospos_items`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_items_taxes`
--

CREATE TABLE IF NOT EXISTS `ospos_items_taxes` (
  `item_id` int(10) NOT NULL,
  `name` varchar(255) NOT NULL,
  `percent` double(15,3) NOT NULL,
  PRIMARY KEY (`item_id`,`name`,`percent`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_items_taxes`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_item_kits`
--

CREATE TABLE IF NOT EXISTS `ospos_item_kits` (
  `item_kit_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `description` varchar(255) NOT NULL,
  PRIMARY KEY (`item_kit_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `ospos_item_kits`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_item_kit_items`
--

CREATE TABLE IF NOT EXISTS `ospos_item_kit_items` (
  `item_kit_id` int(11) NOT NULL,
  `item_id` int(11) NOT NULL,
  `quantity` double(15,2) NOT NULL,
  PRIMARY KEY (`item_kit_id`,`item_id`,`quantity`),
  KEY `ospos_item_kit_items_ibfk_2` (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_item_kit_items`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_modules`
--

CREATE TABLE IF NOT EXISTS `ospos_modules` (
  `name_lang_key` varchar(255) NOT NULL,
  `desc_lang_key` varchar(255) NOT NULL,
  `sort` int(10) NOT NULL,
  `module_id` varchar(255) NOT NULL,
  PRIMARY KEY (`module_id`),
  UNIQUE KEY `desc_lang_key` (`desc_lang_key`),
  UNIQUE KEY `name_lang_key` (`name_lang_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_modules`
--

INSERT INTO `ospos_modules` (`name_lang_key`, `desc_lang_key`, `sort`, `module_id`) VALUES
('module_config', 'module_config_desc', 100, 'config'),
('module_customers', 'module_customers_desc', 10, 'customers'),
('module_employees', 'module_employees_desc', 80, 'employees'),
('module_giftcards', 'module_giftcards_desc', 90, 'giftcards'),
('module_items', 'module_items_desc', 20, 'items'),
('module_item_kits', 'module_item_kits_desc', 30, 'item_kits'),
('module_receivings', 'module_receivings_desc', 60, 'receivings'),
('module_reports', 'module_reports_desc', 50, 'reports'),
('module_sales', 'module_sales_desc', 70, 'sales'),
('module_suppliers', 'module_suppliers_desc', 40, 'suppliers');

-- --------------------------------------------------------

--
-- Table structure for table `ospos_people`
--

CREATE TABLE IF NOT EXISTS `ospos_people` (
  `first_name` varchar(255) NOT NULL,
  `last_name` varchar(255) NOT NULL,
  `phone_number` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `address_1` varchar(255) NOT NULL,
  `address_2` varchar(255) NOT NULL,
  `city` varchar(255) NOT NULL,
  `state` varchar(255) NOT NULL,
  `zip` varchar(255) NOT NULL,
  `country` varchar(255) NOT NULL,
  `comments` text NOT NULL,
  `person_id` int(10) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`person_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `ospos_people`
--

INSERT INTO `ospos_people` (`first_name`, `last_name`, `phone_number`, `email`, `address_1`, `address_2`, `city`, `state`, `zip`, `country`, `comments`, `person_id`) VALUES
('John', 'Doe', '555-555-5555', 'admin@pappastech.com', 'Address 1', '', '', '', '', '', '', 1);

-- --------------------------------------------------------

--
-- Table structure for table `ospos_permissions`
--

CREATE TABLE IF NOT EXISTS `ospos_permissions` (
  `module_id` varchar(255) NOT NULL,
  `person_id` int(10) NOT NULL,
  PRIMARY KEY (`module_id`,`person_id`),
  KEY `person_id` (`person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_permissions`
--

INSERT INTO `ospos_permissions` (`module_id`, `person_id`) VALUES
('config', 1),
('customers', 1),
('employees', 1),
('giftcards', 1),
('items', 1),
('item_kits', 1),
('receivings', 1),
('reports', 1),
('sales', 1),
('suppliers', 1);

-- --------------------------------------------------------

--
-- Table structure for table `ospos_receivings`
--

CREATE TABLE IF NOT EXISTS `ospos_receivings` (
  `receiving_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `supplier_id` int(10) DEFAULT NULL,
  `employee_id` int(10) NOT NULL DEFAULT '0',
  `comment` text NOT NULL,
  `senior` varchar(40) NOT NULL,
  `take_type` varchar(40) NOT NULL,
  `receiving_id` int(10) NOT NULL AUTO_INCREMENT,
  `payment_type` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`receiving_id`),
  KEY `supplier_id` (`supplier_id`),
  KEY `employee_id` (`employee_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `ospos_receivings`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_receivings_items`
--

CREATE TABLE IF NOT EXISTS `ospos_receivings_items` (
  `receiving_id` int(10) NOT NULL DEFAULT '0',
  `item_id` int(10) NOT NULL DEFAULT '0',
  `description` varchar(30) DEFAULT NULL,
  `serialnumber` varchar(30) DEFAULT NULL,
  `line` int(3) NOT NULL,
  `quantity_purchased` int(10) NOT NULL DEFAULT '0',
  `item_cost_price` decimal(15,2) NOT NULL,
  `item_unit_price` double(15,2) NOT NULL,
  `discount_percent` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`receiving_id`,`item_id`,`line`),
  KEY `item_id` (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_receivings_items`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_sales`
--

CREATE TABLE IF NOT EXISTS `ospos_sales` (
  `sale_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `customer_id` int(10) DEFAULT NULL,
  `employee_id` int(10) NOT NULL DEFAULT '0',
  `comment` text NOT NULL,
  `senior` varchar(40) NOT NULL,
  `take_type` varchar(40) NOT NULL,
  `sale_id` int(6) unsigned zerofill NOT NULL AUTO_INCREMENT,
  `payment_type` varchar(512) DEFAULT NULL,
  PRIMARY KEY (`sale_id`),
  KEY `customer_id` (`customer_id`),
  KEY `employee_id` (`employee_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `ospos_sales`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_sales_items`
--

CREATE TABLE IF NOT EXISTS `ospos_sales_items` (
  `sale_id` int(6) unsigned zerofill NOT NULL DEFAULT '000000',
  `item_id` int(10) NOT NULL DEFAULT '0',
  `description` varchar(30) DEFAULT NULL,
  `serialnumber` varchar(30) DEFAULT NULL,
  `line` int(3) NOT NULL DEFAULT '0',
  `quantity_purchased` double(15,2) NOT NULL DEFAULT '0.00',
  `item_cost_price` decimal(15,2) NOT NULL,
  `item_unit_price` double(15,2) NOT NULL,
  `discount_percent` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`sale_id`,`item_id`,`line`),
  KEY `item_id` (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_sales_items`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_sales_items_taxes`
--

CREATE TABLE IF NOT EXISTS `ospos_sales_items_taxes` (
  `sale_id` int(6) unsigned zerofill NOT NULL,
  `item_id` int(10) NOT NULL,
  `line` int(3) NOT NULL DEFAULT '0',
  `name` varchar(255) NOT NULL,
  `percent` double(15,3) NOT NULL,
  PRIMARY KEY (`sale_id`,`item_id`,`line`,`name`,`percent`),
  KEY `item_id` (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_sales_items_taxes`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_sales_payments`
--

CREATE TABLE IF NOT EXISTS `ospos_sales_payments` (
  `sale_id` int(6) unsigned zerofill NOT NULL,
  `payment_type` varchar(40) NOT NULL,
  `payment_amount` decimal(15,2) NOT NULL,
  PRIMARY KEY (`sale_id`,`payment_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_sales_payments`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_sales_suspended`
--

CREATE TABLE IF NOT EXISTS `ospos_sales_suspended` (
  `sale_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `customer_id` int(10) DEFAULT NULL,
  `employee_id` int(10) NOT NULL DEFAULT '0',
  `comment` text NOT NULL,
  `sale_id` int(6) unsigned zerofill NOT NULL AUTO_INCREMENT,
  `payment_type` varchar(512) DEFAULT NULL,
  PRIMARY KEY (`sale_id`),
  KEY `customer_id` (`customer_id`),
  KEY `employee_id` (`employee_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `ospos_sales_suspended`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_sales_suspended_items`
--

CREATE TABLE IF NOT EXISTS `ospos_sales_suspended_items` (
  `sale_id` int(6) unsigned zerofill NOT NULL DEFAULT '000000',
  `item_id` int(10) NOT NULL DEFAULT '0',
  `description` varchar(30) DEFAULT NULL,
  `serialnumber` varchar(30) DEFAULT NULL,
  `line` int(3) NOT NULL DEFAULT '0',
  `quantity_purchased` double(15,2) NOT NULL DEFAULT '0.00',
  `item_cost_price` decimal(15,2) NOT NULL,
  `item_unit_price` double(15,2) NOT NULL,
  `discount_percent` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`sale_id`,`item_id`,`line`),
  KEY `item_id` (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_sales_suspended_items`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_sales_suspended_items_taxes`
--

CREATE TABLE IF NOT EXISTS `ospos_sales_suspended_items_taxes` (
  `sale_id` int(6) unsigned zerofill NOT NULL,
  `item_id` int(10) NOT NULL,
  `line` int(3) NOT NULL DEFAULT '0',
  `name` varchar(255) NOT NULL,
  `percent` double(15,3) NOT NULL,
  PRIMARY KEY (`sale_id`,`item_id`,`line`,`name`,`percent`),
  KEY `item_id` (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_sales_suspended_items_taxes`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_sales_suspended_payments`
--

CREATE TABLE IF NOT EXISTS `ospos_sales_suspended_payments` (
  `sale_id` int(6) unsigned zerofill NOT NULL,
  `payment_type` varchar(40) NOT NULL,
  `payment_amount` decimal(15,2) NOT NULL,
  PRIMARY KEY (`sale_id`,`payment_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_sales_suspended_payments`
--

-- --------------------------------------------------------

--
-- Table structure for table `ospos_sessions`
--

CREATE TABLE IF NOT EXISTS `ospos_sessions` (
  `session_id` varchar(40) NOT NULL DEFAULT '0',
  `ip_address` varchar(16) NOT NULL DEFAULT '0',
  `user_agent` varchar(120) NOT NULL,
  `last_activity` int(10) unsigned NOT NULL DEFAULT '0',
  `user_data` text,
  PRIMARY KEY (`session_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_sessions`
--

INSERT INTO `ospos_sessions` (`session_id`, `ip_address`, `user_agent`, `last_activity`, `user_data`) VALUES
('1ca9d18adceed8b80920254cd17c0134', '127.0.0.1', 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0', 1410704762, 'a:6:{s:9:"user_data";s:0:"";s:9:"person_id";s:1:"1";s:4:"cart";a:0:{}s:9:"sale_mode";s:4:"sale";s:8:"customer";i:-1;s:8:"payments";a:0:{}}');

-- --------------------------------------------------------

--
-- Table structure for table `ospos_suppliers`
--

CREATE TABLE IF NOT EXISTS `ospos_suppliers` (
  `person_id` int(10) NOT NULL,
  `company_name` varchar(255) NOT NULL,
  `account_number` varchar(255) DEFAULT NULL,
  `deleted` int(1) NOT NULL DEFAULT '0',
  UNIQUE KEY `account_number` (`account_number`),
  KEY `person_id` (`person_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping data for table `ospos_suppliers`
--

--
-- Constraints for dumped tables
--

--
-- Constraints for table `ospos_customers`
--
ALTER TABLE `ospos_customers`
  ADD CONSTRAINT `ospos_customers_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);

--
-- Constraints for table `ospos_employees`
--
ALTER TABLE `ospos_employees`
  ADD CONSTRAINT `ospos_employees_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_people` (`person_id`);

--
-- Constraints for table `ospos_inventory`
--
ALTER TABLE `ospos_inventory`
  ADD CONSTRAINT `ospos_inventory_ibfk_1` FOREIGN KEY (`trans_items`) REFERENCES `ospos_items` (`item_id`),
  ADD CONSTRAINT `ospos_inventory_ibfk_2` FOREIGN KEY (`trans_user`) REFERENCES `ospos_employees` (`person_id`);

--
-- Constraints for table `ospos_items`
--
ALTER TABLE `ospos_items`
  ADD CONSTRAINT `ospos_items_ibfk_1` FOREIGN KEY (`supplier_id`) REFERENCES `ospos_suppliers` (`person_id`);

--
-- Constraints for table `ospos_items_taxes`
--
ALTER TABLE `ospos_items_taxes`
  ADD CONSTRAINT `ospos_items_taxes_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `ospos_items` (`item_id`) ON DELETE CASCADE;

--
-- Constraints for table `ospos_item_kit_items`
--
ALTER TABLE `ospos_item_kit_items`
  ADD CONSTRAINT `ospos_item_kit_items_ibfk_1` FOREIGN KEY (`item_kit_id`) REFERENCES `ospos_item_kits` (`item_kit_id`) ON DELETE CASCADE,
  ADD CONSTRAINT `ospos_item_kit_items_ibfk_2` FOREIGN KEY (`item_id`) REFERENCES `ospos_items` (`item_id`) ON DELETE CASCADE;

--
-- Constraints for table `ospos_permissions`
--
ALTER TABLE `ospos_permissions`
  ADD CONSTRAINT `ospos_permissions_ibfk_1` FOREIGN KEY (`person_id`) REFERENCES `ospos_employees` (`person_id`),
  ADD CONSTRAINT `ospos_permissions_ibfk_2` FOREIGN KEY (`module_id`) REFERENCES `ospos_modules` (`module_id`);

--
-- Constraints for table `ospos_receivings`
--
ALTER TABLE `ospos_receivings`
  ADD CONSTRAINT `ospos_receivings_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `ospos_employees` (`person_id`),
  ADD CONSTRAINT `ospos_receivings_ibfk_2` FOREIGN KEY (`supplier_id`) REFERENCES `ospos_suppliers` (`person_id`);

--
-- Constraints for table `ospos_receivings_items`
--
ALTER TABLE `ospos_receivings_items`
  ADD CONSTRAINT `ospos_receivings_items_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `ospos_items` (`item_id`),
  ADD CONSTRAINT `ospos_receivings_items_ibfk_2` FOREIGN KEY (`receiving_id`) REFERENCES `ospos_receivings` (`receiving_id`);

--
-- Constraints for table `ospos_sales`
--
ALTER TABLE `ospos_sales`
  ADD CONSTRAINT `ospos_sales_ibfk_1` FOREIGN KEY (`employee_id`) REFERENCES `ospos_employees` (`person_id`),
  ADD CONSTRAINT `ospos_sales_ibfk_2` FOREIGN KEY (`customer_id`) REFERENCES `ospos_customers` (`person_id`);

--
-- Constraints for table `ospos_sales_items`
--
ALTER TABLE `ospos_sales_items`
  ADD CONSTRAINT `ospos_sales_items_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `ospos_items` (`item_id`),
  ADD CONSTRAINT `ospos_sales_items_ibfk_2` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales` (`sale_id`);

--
-- Constraints for table `ospos_sales_items_taxes`
--
ALTER TABLE `ospos_sales_items_taxes`
  ADD CONSTRAINT `ospos_sales_items_taxes_ibfk_1` FOREIGN KEY (`sale_id`) REFERENCES `ospos_sales_items` (`sale_id`),


text:
SELECT * FROM (SELECT *
FROM (
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu2", qview2."stringu1", qview3."evenonepercent", qview3."stringu2", qview3."stringu1"
FROM
"public"."t16_1m" qview1,
"public"."t17_1m" qview2,
"public"."t18_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu2", qview2."stringu1", qview3."evenonepercent", qview3."stringu1", qview3."string4"
FROM
"public"."t16_1m" qview1,
"public"."t17_1m" qview2,
"public"."t15_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu1" IS NOT NULL AND
qview3."string4" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu2", qview2."stringu1", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t17_1m" qview2,
"public"."t12_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu2", qview2."stringu1", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t17_1m" qview2,
"public"."t9_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu2", qview2."stringu1", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t17_1m" qview2,
"public"."t6_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu2", qview2."stringu1", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t17_1m" qview2,
"public"."t3_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."string4", qview3."evenonepercent", qview3."stringu2", qview3."stringu1"
FROM
"public"."t16_1m" qview1,
"public"."t14_1m" qview2,
"public"."t18_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
qview2."string4" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."string4", qview3."evenonepercent", qview3."stringu1", qview3."string4"
FROM
"public"."t16_1m" qview1,
"public"."t14_1m" qview2,
"public"."t15_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
qview2."string4" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu1" IS NOT NULL AND
qview3."string4" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."string4", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t14_1m" qview2,
"public"."t12_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
qview2."string4" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."string4", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t14_1m" qview2,
"public"."t9_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
qview2."string4" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."string4", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t14_1m" qview2,
"public"."t6_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
qview2."string4" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."string4", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t14_1m" qview2,
"public"."t3_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
qview2."string4" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."stringu2", qview3."evenonepercent", qview3."stringu2", qview3."stringu1"
FROM
"public"."t16_1m" qview1,
"public"."t11_1m" qview2,
"public"."t18_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."stringu2", qview3."evenonepercent", qview3."stringu1", qview3."string4"
FROM
"public"."t16_1m" qview1,
"public"."t11_1m" qview2,
"public"."t15_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu1" IS NOT NULL AND
qview3."string4" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."stringu2", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t11_1m" qview2,
"public"."t12_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."stringu2", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t11_1m" qview2,
"public"."t9_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."stringu2", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t11_1m" qview2,
"public"."t6_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."stringu2", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t11_1m" qview2,
"public"."t3_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."stringu2", qview3."evenonepercent", qview3."stringu2", qview3."stringu1"
FROM
"public"."t16_1m" qview1,
"public"."t8_1m" qview2,
"public"."t18_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."stringu2", qview3."evenonepercent", qview3."stringu1", qview3."string4"
FROM
"public"."t16_1m" qview1,
"public"."t8_1m" qview2,
"public"."t15_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu1" IS NOT NULL AND
qview3."string4" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."stringu2", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t8_1m" qview2,
"public"."t12_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND
qview1."evenonepercent" IS NOT NULL AND
qview1."stringu2" IS NOT NULL AND
qview1."stringu1" IS NOT NULL AND
qview1."unique2" IS NOT NULL AND
(qview1."unique2" = qview2."unique2") AND
((qview2."onepercent" >= 0) AND (qview2."onepercent" < 20)) AND
qview2."evenonepercent" IS NOT NULL AND
qview2."stringu2" IS NOT NULL AND
qview2."stringu1" IS NOT NULL AND
(qview1."unique2" = qview3."unique2") AND
((qview3."onepercent" >= 0) AND (qview3."onepercent" < 20)) AND
qview3."evenonepercent" IS NOT NULL AND
qview3."stringu2" IS NOT NULL AND
qview3."stringu1" IS NOT NULL
UNION
SELECT qview1."unique2", qview1."evenonepercent", qview1."stringu2", qview1."stringu1", qview2."evenonepercent", qview2."stringu1", qview2."stringu2", qview3."evenonepercent", qview3."stringu1", qview3."stringu2"
FROM
"public"."t16_1m" qview1,
"public"."t8_1m" qview2,
"public"."t9_1m" qview3
WHERE
((qview1."onepercent" >= 0) AND (qview1."onepercent" < 20)) AND

domain: sql


text:
select dimensions_editions.warehouse_item_id as warehouse_item_id,
  dimensions_editions.title as title,
  dimensions_editions.document_type as document_type,
  dimensions_editions.base_path as base_path,
  dimensions_editions.primary_organisation_id as primary_organisation_id,
  dimensions_editions.id as dimensions_edition_id,
  aggregations.upviews::bigint as upviews,
  aggregations.pviews::bigint as pviews,
  aggregations.feedex::bigint as feedex,
  aggregations.useful_yes::bigint as useful_yes,
  aggregations.useful_no::bigint as useful_no,
  CURRENT_DATE as updated_at,
  CASE
    WHEN useful_yes + useful_no = 0 THEN NULL
    ELSE useful_yes::float / (useful_yes + useful_no)
  END as satisfaction,
  aggregations.searches::bigint as searches,
  facts_editions.words as words,
  facts_editions.pdf_count as pdf_count,
  facts_editions.reading_time as reading_time
FROM
  (
      SELECT  warehouse_item_id,
      max(aggregations_monthly_metrics.dimensions_edition_id) AS dimensions_edition_id,
      sum(aggregations_monthly_metrics.upviews) AS upviews,
      sum(aggregations_monthly_metrics.pviews) AS pviews,
      sum(aggregations_monthly_metrics.useful_yes) AS useful_yes,
      sum(aggregations_monthly_metrics.useful_no) AS useful_no,
      sum(aggregations_monthly_metrics.feedex) AS feedex,
      sum(aggregations_monthly_metrics.searches) AS searches
    FROM aggregations_monthly_metrics
    INNER JOIN dimensions_months ON dimensions_months.id = aggregations_monthly_metrics.dimensions_month_id
    INNER JOIN dimensions_editions ON dimensions_editions.id = aggregations_monthly_metrics.dimensions_edition_id
    WHERE dimensions_months.id = to_char(NOW() - interval '1 month','YYYY-MM')
    GROUP BY warehouse_item_id
  ) as aggregations
INNER JOIN dimensions_editions ON aggregations.dimensions_edition_id = dimensions_editions.id
INNER JOIN facts_editions ON dimensions_editions.id = facts_editions.dimensions_edition_id
WHERE dimensions_editions.document_type NOT IN ('gone','vanish','need','unpublishing','redirect')


text:
SELECT
eu_decisions.id,
eu_decisions.type,
eu_decisions.taxon_concept_id,
ROW_TO_JSON(
 ROW(
   taxon_concept_id,
   taxon_concepts.full_name,
   taxon_concepts.author_year,
   taxon_concepts.data->'rank_name'
 )::api_taxon_concept
) AS taxon_concept,
eu_decisions.notes,
CASE
  WHEN eu_decisions.type = 'EuOpinion'
  THEN eu_decisions.start_date::DATE
  WHEN eu_decisions.type = 'EuSuspension'
  THEN start_event.effective_at::DATE
END AS start_date,
CASE
  WHEN eu_decisions.type = 'EuOpinion'
  THEN eu_decisions.is_current
  WHEN eu_decisions.type = 'EuSuspension'
  THEN
    CASE
      WHEN start_event.effective_at <= current_date AND start_event.is_current = true
        AND (eu_decisions.end_event_id IS NULL OR end_event.effective_at > current_date)
      THEN TRUE
      ELSE
        FALSE
    END
END AS is_current,
eu_decisions.geo_entity_id,
ROW_TO_JSON(
  ROW(
    geo_entities.iso_code2,
    geo_entities.name_en,
    geo_entity_types.name
  )::api_geo_entity
) AS geo_entity_en,
ROW_TO_JSON(
  ROW(
    geo_entities.iso_code2,
    geo_entities.name_es,
    geo_entity_types.name
  )::api_geo_entity
) AS geo_entity_es,
ROW_TO_JSON(
  ROW(
    geo_entities.iso_code2,
    geo_entities.name_fr,
    geo_entity_types.name
  )::api_geo_entity
) AS geo_entity_fr,
eu_decisions.start_event_id,
ROW_TO_JSON(
  ROW(
    start_event.name || CASE WHEN start_event.type = 'EcSrg' THEN ' Soc' ELSE '' END,
    start_event.effective_at::DATE,
    start_event.url
  )::api_event
) AS start_event,
eu_decisions.end_event_id,
ROW_TO_JSON(
  ROW(
    end_event.name,
    end_event.effective_at::DATE,
    end_event.url
  )::api_event
) AS end_event,
eu_decisions.term_id,
ROW_TO_JSON(
  ROW(
    terms.code,
    terms.name_en
  )::api_trade_code
) AS term_en,
ROW_TO_JSON(
  ROW(
    terms.code,
    terms.name_es
  )::api_trade_code
) AS term_es,
ROW_TO_JSON(
  ROW(
    terms.code,
    terms.name_fr
  )::api_trade_code
) AS term_fr,
ROW_TO_JSON(
  ROW(
    sources.code,
    sources.name_en
  )::api_trade_code
) AS source_en,
ROW_TO_JSON(
  ROW(
    sources.code,
    sources.name_es
  )::api_trade_code
) AS source_es,
ROW_TO_JSON(
  ROW(
    sources.code,
    sources.name_fr
  )::api_trade_code
) AS source_fr,
eu_decisions.source_id,
eu_decisions.eu_decision_type_id,
ROW_TO_JSON(
  ROW(
    eu_decision_types.name,
    eu_decision_types.tooltip,
    eu_decision_types.decision_type
  )::api_eu_decision_type
) AS eu_decision_type,
eu_decisions.srg_history_id,
ROW_TO_JSON(
  ROW(
    srg_histories.name,
    srg_histories.tooltip
  )::api_srg_history
) AS srg_history,
eu_decisions.nomenclature_note_en,
eu_decisions.nomenclature_note_fr,
eu_decisions.nomenclature_note_es
FROM eu_decisions
JOIN geo_entities ON geo_entities.id = eu_decisions.geo_entity_id
JOIN geo_entity_types ON geo_entities.geo_entity_type_id = geo_entity_types.id
JOIN taxon_concepts ON taxon_concepts.id = eu_decisions.taxon_concept_id
LEFT JOIN events AS start_event ON start_event.id = eu_decisions.start_event_id
LEFT JOIN events AS end_event ON end_event.id = eu_decisions.end_event_id
LEFT JOIN trade_codes terms ON terms.id = eu_decisions.term_id AND terms.type = 'Term'
LEFT JOIN trade_codes sources ON sources.id = eu_decisions.source_id AND sources.type = 'Source'
LEFT JOIN eu_decision_types ON eu_decision_types.id = eu_decisions.eu_decision_type_id
LEFT JOIN srg_histories ON srg_histories.id = eu_decisions.srg_history_id;


text:
-- SPDX-License-Identifier: Apache-2.0
-- Licensed to the Ed-Fi Alliance under one or more agreements.
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
-- See the LICENSE and NOTICES files in the project root for more information.

PRINT N'Dropping type reference from [edfi].[ExitWithdrawTypeDescriptor]'
GO

ALTER TABLE [edfi].[ExitWithdrawTypeDescriptor]
DROP COLUMN [ExitWithdrawTypeId]
GO

PRINT N'Importing updated ExitWithdrawTypeDescriptor defaults'
GO

EXEC [migration_tempdata].[sp_ImportDescriptorsFromXML] 'ExitWithdrawTypeDescriptor'
GO


text:
-- Migrationscripts for ebean unittest
-- drop dependencies
drop view if exists migtest_e_history2_with_history;
drop view if exists migtest_e_history3_with_history;
drop view if exists migtest_e_history4_with_history;

-- apply changes
create table migtest_e_ref (
  id                            integer generated by default as identity not null,
  name                          varchar(127) not null,
  constraint uq_migtest_e_ref_name unique (name),
  constraint pk_migtest_e_ref primary key (id)
);

alter table if exists migtest_ckey_detail drop constraint if exists fk_migtest_ckey_detail_parent;
alter table if exists migtest_fk_cascade drop constraint if exists fk_migtest_fk_cascade_one_id;
alter table migtest_fk_cascade add constraint fk_migtest_fk_cascade_one_id foreign key (one_id) references migtest_fk_cascade_one (id) on delete cascade on update restrict;
alter table if exists migtest_fk_none drop constraint if exists fk_migtest_fk_none_one_id;
alter table if exists migtest_fk_none_via_join drop constraint if exists fk_migtest_fk_none_via_join_one_id;
alter table if exists migtest_fk_set_null drop constraint if exists fk_migtest_fk_set_null_one_id;
alter table migtest_fk_set_null add constraint fk_migtest_fk_set_null_one_id foreign key (one_id) references migtest_fk_one (id) on delete set null on update restrict;
alter table migtest_e_basic drop constraint if exists ck_migtest_e_basic_status;
alter table migtest_e_basic alter column status drop default;
alter table migtest_e_basic alter column status drop not null;
alter table migtest_e_basic add constraint ck_migtest_e_basic_status check ( status in ('N','A','I'));

update migtest_e_basic set status2 = 'N' where status2 is null;
alter table migtest_e_basic drop constraint if exists ck_migtest_e_basic_status2;
alter table migtest_e_basic alter column status2 type varchar(1) using status2::varchar(1);
alter table migtest_e_basic alter column status2 set default 'N';
alter table migtest_e_basic alter column status2 set not null;
alter table migtest_e_basic add constraint ck_migtest_e_basic_status2 check ( status2 in ('N','A','I'));
alter table migtest_e_basic drop constraint uq_migtest_e_basic_description;

update migtest_e_basic set user_id = 23 where user_id is null;
alter table if exists migtest_e_basic drop constraint if exists fk_migtest_e_basic_user_id;
alter table migtest_e_basic alter column user_id set default 23;
alter table migtest_e_basic alter column user_id set not null;
alter table migtest_e_basic add column description_file bytea;
alter table migtest_e_basic add column old_boolean boolean default false not null;
alter table migtest_e_basic add column old_boolean2 boolean;
alter table migtest_e_basic add column eref_id integer;

alter table migtest_e_basic drop constraint uq_migtest_e_basic_status_indextest1;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_name;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest4;
alter table migtest_e_basic drop constraint uq_migtest_e_basic_indextest5;
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest2 unique  (indextest2);
alter table migtest_e_basic add constraint uq_migtest_e_basic_indextest6 unique  (indextest6);
alter table migtest_e_enum drop constraint if exists ck_migtest_e_enum_test_status;
alter table migtest_e_enum add constraint ck_migtest_e_enum_test_status check ( test_status in ('N','A','I'));
comment on column migtest_e_history.test_string is '';
comment on table migtest_e_history is '';
alter table migtest_e_history2 alter column test_string drop default;
alter table migtest_e_history2 alter column test_string drop not null;
alter table migtest_e_history2 add column obsolete_string1 varchar(255);
alter table migtest_e_history2 add column obsolete_string2 varchar(255);
alter table migtest_e_history2_history add column obsolete_string1 varchar(255);
alter table migtest_e_history2_history add column obsolete_string2 varchar(255);

alter table migtest_e_history4 alter column test_number type integer using test_number::integer;
alter table migtest_e_history4_history alter column test_number type integer using test_number::integer;
alter table migtest_e_history6 alter column test_number1 drop default;
alter table migtest_e_history6 alter column test_number1 drop not null;

-- NOTE: table has @History - special migration may be necessary
update migtest_e_history6 set test_number2 = 7 where test_number2 is null;
alter table migtest_e_history6 alter column test_number2 set default 7;
alter table migtest_e_history6 alter column test_number2 set not null;
create index if not exists ix_migtest_e_basic_indextest1 on migtest_e_basic (indextest1);
create index if not exists ix_migtest_e_basic_indextest5 on migtest_e_basic (indextest5);
create index if not exists ix_m12_otoc71 on migtest_oto_child (name);
create unique index if not exists uq_m12_otoc71 on migtest_oto_child (lower(name));
create unique index if not exists ix_migtest_oto_master_lowername on migtest_oto_master (lower(name));
drop index if exists ix_migtest_e_basic_indextest3;
drop index if exists ix_migtest_e_basic_indextest6;
create index ix_migtest_e_basic_eref_id on migtest_e_basic (eref_id);
alter table migtest_e_basic add constraint fk_migtest_e_basic_eref_id foreign key (eref_id) references migtest_e_ref (id) on delete restrict on update restrict;

create view migtest_e_history2_with_history as select * from migtest_e_history2 union all select * from migtest_e_history2_history;

create view migtest_e_history3_with_history as select * from migtest_e_history3 union all select * from migtest_e_history3_history;

create view migtest_e_history4_with_history as select * from migtest_e_history4 union all select * from migtest_e_history4_history;

-- changes: [add obsolete_string1, add obsolete_string2]
create or replace function migtest_e_history2_history_version() returns trigger as $$
declare
  lowerTs timestamptz;
  upperTs timestamptz;
begin
  lowerTs = lower(OLD.sys_period);
  upperTs = greatest(lowerTs + '1 microsecond',current_timestamp);
  if (TG_OP = 'UPDATE') then
    insert into migtest_e_history2_history (sys_period,id, test_string, obsolete_string2, test_string2, test_string3, new_column) values (tstzrange(lowerTs,upperTs), OLD.id, OLD.test_string, OLD.obsolete_string2, OLD.test_string2, OLD.test_string3, OLD.new_column);
    NEW.sys_period = tstzrange(upperTs,null);
    return new;
  elsif (TG_OP = 'DELETE') then
    insert into migtest_e_history2_history (sys_period,id, test_string, obsolete_string2, test_string2, test_string3, new_column) values (tstzrange(lowerTs,upperTs), OLD.id, OLD.test_string, OLD.obsolete_string2, OLD.test_string2, OLD.test_string3, OLD.new_column);
    return old;
  end if;
end;
$$ LANGUAGE plpgsql;

-- changes: [include test_string]
create or replace function migtest_e_history3_history_version() returns trigger as $$
declare
  lowerTs timestamptz;
  upperTs timestamptz;
begin
  lowerTs = lower(OLD.sys_period);
  upperTs = greatest(lowerTs + '1 microsecond',current_timestamp);
  if (TG_OP = 'UPDATE') then
    insert into migtest_e_history3_history (sys_period,id, test_string) values (tstzrange(lowerTs,upperTs), OLD.id, OLD.test_string);
    NEW.sys_period = tstzrange(upperTs,null);
    return new;
  elsif (TG_OP = 'DELETE') then
    insert into migtest_e_history3_history (sys_period,id, test_string) values (tstzrange(lowerTs,upperTs), OLD.id, OLD.test_string);
    return old;
  end if;
end;
$$ LANGUAGE plpgsql;

-- changes: [alter test_number]
create or replace function migtest_e_history4_history_version() returns trigger as $$
declare
  lowerTs timestamptz;
  upperTs timestamptz;
begin
  lowerTs = lower(OLD.sys_period);
  upperTs = greatest(lowerTs + '1 microsecond',current_timestamp);
  if (TG_OP = 'UPDATE') then
    insert into migtest_e_history4_history (sys_period,id, test_number) values (tstzrange(lowerTs,upperTs), OLD.id, OLD.test_number);
    NEW.sys_period = tstzrange(upperTs,null);
    return new;
  elsif (TG_OP = 'DELETE') then
    insert into migtest_e_history4_history (sys_period,id, test_number) values (tstzrange(lowerTs,upperTs), OLD.id, OLD.test_number);
    return old;
  end if;
end;
$$ LANGUAGE plpgsql;


text:
--
--
--  triggers, not null, exclusions and check
-- all work exactly the same given the bitemporal constraints
--
-- 3 constraints do not. primary key, foreign key and unique constraints.
--

-- create the three types of constraints.
--   need strings to include in a create table
--   need commands to modify existing table

-- find the a particular set of constraints given a table
--

create or replace
function bitemporal_internal.conname_prefix() returns text
language sql IMMUTABLE as $f$
    select 'bitemporal'::text;
$f$;

create or replace
function bitemporal_internal.mk_conname(con_type text, src_column text, fk_table text, fk_column text )
returns text
language sql IMMUTABLE
as $f$
select substring(format('%s %s %s%s%s', conname_prefix()
                   , con_type
                   , src_column
                   , fk_table, fk_column)
          from 0 for 64 );
$f$
SET search_path = 'bitemporal_internal';

create or replace
function bitemporal_internal.mk_constraint(con_type text, con_name text, con_src text)
returns text
language sql IMMUTABLE
as $ff$
  select format($$CONSTRAINT %I check(true or '%s' <> '@%s@') $$
        , con_name
        , con_type
        , con_src)::text;
$ff$;

create or replace
function bitemporal_internal.pk_constraint(src_column text)
returns text
language sql IMMUTABLE as $f$
  select mk_constraint('pk', mk_conname('pk', src_column, '', '') , src_column);
$f$
SET search_path = 'bitemporal_internal';

create or replace
function bitemporal_internal.fk_constraint(src_column text, fk_table text, fk_column text, connname text)
returns text
language sql IMMUTABLE
as $ff$
  select mk_constraint('fk'
             , connname
             , format('%s -> %s(%s)', src_column, fk_table, fk_column) );
$ff$
SET search_path = 'bitemporal_internal';

create or replace
function bitemporal_internal.fk_constraint(src_column text, fk_table text, fk_column text)
returns text
language sql IMMUTABLE
as $ff$
  select fk_constraint(src_column , fk_table , fk_column,
          mk_conname('fk', src_column, fk_table, fk_column));
$ff$
SET search_path = 'bitemporal_internal';

create or replace
function bitemporal_internal.unique_constraint(src_column text)
returns setof text
language sql IMMUTABLE
as $f$
  values ( mk_constraint('u'
             , mk_conname('u', src_column, '','')
             , format('%s', src_column) )),
       (format('CONSTRAINT %I EXCLUDE USING gist (%I WITH =, asserted WITH &&, effective WITH &&)'
             , mk_conname('unique', src_column, '', '')
             , src_column)::text)

    ;
--   CONSTRAINT devices_device_id_asserted_effective_excl EXCLUDE
--  USING gist (device_id WITH =, asserted WITH &&, effective WITH &&)
$f$
SET search_path = 'bitemporal_internal';

create or replace
function bitemporal_internal.add_constraint(table_name text, _con text)
returns text
language sql IMMUTABLE
as $f$
  select format('alter table %s add %s', table_name, _con)::text;
$f$;

create or replace
function bitemporal_internal.select_constraint_value(src text)
returns  text
language plpgsql IMMUTABLE
as $f$
DECLARE
  at int;
  s   text;
BEGIN
-- select inside @ @
  at := strpos(src, '@');
  s  := substr(src, at + 1 );
  at := strpos(s, '@');
  return substring(s from 0::int for at );
END;
$f$;

create
type bitemporal_internal.bitemporal_pg_constraint
as
(
oid	oid
,conname	name
,connamespace	oid
,contype	"char"
,condeferrable	bool
,condeferred	bool
,convalidated	bool
,conrelid	oid
,contypid	oid
,conindid	oid
-- ,conparentid	oid
,confrelid	oid
,confupdtype	"char"
,confdeltype	"char"
,confmatchtype	"char"
,conislocal	bool
,coninhcount	int4
,connoinherit	bool
,conkey	int2[]
,confkey	int2[]
,conpfeqop	oid[]
,conppeqop	oid[]
,conffeqop	oid[]
,conexclop	oid[]
,conbin	pg_node_tree
, consrc	text
);

create or replace
function bitemporal_internal.find_constraints(table_name text, _criteria text )
returns setof  bitemporal_internal.bitemporal_pg_constraint
language sql IMMUTABLE
as $f$
    select oid, conname, connamespace, contype,
      condeferrable, condeferred,convalidated,
  conrelid, contypid, conindid, /* conparentid,*/ confrelid,
  confupdtype, confdeltype, confmatchtype, conislocal,
  coninhcount	, connoinherit, conkey, confkey,
  conpfeqop	, conppeqop	, conffeqop	, conexclop	, conbin
       , pg_get_expr(conbin, conrelid) as consrc -- .pg_get_constraintdef()
       from pg_constraint
       where conrelid = cast(table_name as regclass)
       and conname like format('%s %s %%', bitemporal_internal.conname_prefix(), _criteria )
       ;
$f$;

create or replace
function bitemporal_internal.find_pk(table_name text)
returns text
language plpgsql IMMUTABLE
as $f$
DECLARE
    r  record;
BEGIN
    select * into r from bitemporal_internal.find_constraints(table_name, 'pk');
    RETURN bitemporal_internal.select_constraint_value(r.consrc);
END;
$f$;

create table if not exists bitemporal_internal.fk_constraint_type (
   conname name
  , src_column  name
  , fk_table text
  , fk_column name
);

create or replace
function bitemporal_internal.split_out_fk(consrc text)
returns bitemporal_internal.fk_constraint_type
language plpgsql IMMUTABLE
as $f$
DECLARE
    src text;
    ref text;
    rc  fk_constraint_type%ROWTYPE;
    rp int;
    lp int;
BEGIN
    -- format('%s -> %s(%s)', src_column, fk_table, fk_column)
    src := select_constraint_value(consrc) ;
    rc.src_column :=  split_part(src, ' ', 1);
    ref := split_part(src, ' ', 3);
    rp := strpos(ref, '(');
    lp := strpos(ref, ')');
    if (lp < 1 or rp < 1 ) then
      raise notice 'split_out_bitemporal_fk: invaild format "%"', consrc ;
      return NULL;
    end if;
    rc.fk_table := substring(ref from 0 for rp );
    rc.fk_column :=  substring(ref from rp +1 for (lp - rp -1) );
    RETURN rc;
END;
$f$
SET search_path = 'bitemporal_internal';

create or replace
function bitemporal_internal.find_fk(table_name text)
returns setof bitemporal_internal.fk_constraint_type
language plpgsql
as $f$
DECLARE
    rc  bitemporal_internal.fk_constraint_type%ROWTYPE;
    r record;
BEGIN

    for r in select * from bitemporal_internal.find_constraints(table_name, 'fk')
    loop
        rc := bitemporal_internal.split_out_fk(r.consrc);
        rc.conname := r.conname;
        return next  rc;
    end loop;
    RETURN ;
END;
$f$;

/*
       conname       | contype | conrelid |
consrc
---------------------+---------+----------+-----------------------------------------------------------------------------------------
 bitemporal fk 1     | c       |  1625561 | (true OR ('fk'::text <> '@node_id -> sg.networks network_id@'::text))
 bitemporal fk 2     | c       |  1625561 | (true OR ('fk'::text = ANY (ARRAY['node_id'::text, 'cnu.networks'::text, 'id'::text])))
 bitemporal unique 3 | c       |  1625561 | (true OR ('col'::text = 'name'::text))

*/

-- vim: set filetype=pgsql expandtab tabstop=2 shiftwidth=2: