#!/bin/bash if [ -z "$1" ]; then cat < donde \"\" es el nombre de la base de datos a convertir. Como siempre, NO HAY GARANTIA DE QUE NO SE PIERDAN DATOS, y recomendamos correr el script primero contra una base de datos de prueba, y hacer un backup antes de convertir una base de producción. EOF exit 1 fi BASE="$1" OPTS="-q -A -t -h localhost" DB="psql $OPTS $BASE" echo '\d' | $DB > /dev/null || exit 1 $DB < own_pos_document ALTER TABLE branch_document RENAME TO own_pos_document; ALTER TABLE _branch_document_data RENAME TO _own_pos_document_data; ALTER TABLE _own_pos_document_data ADD COLUMN own_pos bigint REFERENCES entity; ALTER TABLE _own_pos_document_data RENAME COLUMN branch TO DEPRECATED_branch; -- cargo un punto de venta INSERT INTO entity (id) VALUES (nextval('entity_id_seq')); INSERT INTO _entity_data (_table, _start_t, name ) VALUES (currval('entity_id_seq'), current_timestamp, 'punto de venta por defecto'); INSERT INTO own_entity (id) VALUES (nextval('own_entity_id_seq')); INSERT INTO _own_entity_data (_table, _start_t, entity ) VALUES (currval('own_entity_id_seq'), current_timestamp, currval('entity_id_seq')); INSERT INTO own_pos (id) values (nextval('own_pos_id_seq')); INSERT INTO _own_pos_data (_table, _start_t, number, stock_by_invoice, own_entity) VALUES (currval('own_pos_id_seq'), current_timestamp, 'uno', true, currval('own_entity_id_seq')); -- carga un storehouse INSERT INTO entity (id) VALUES (nextval('entity_id_seq')); INSERT INTO _entity_data (_table, _start_t, name ) VALUES (currval('entity_id_seq'), current_timestamp, 'depósito por defecto'); INSERT INTO own_entity (id) VALUES (nextval('own_entity_id_seq')); INSERT INTO _own_entity_data (_table, _start_t, entity ) VALUES (currval('own_entity_id_seq'), current_timestamp, currval('entity_id_seq')); INSERT INTO own_storehouse (id) values (nextval('own_storehouse_id_seq')); INSERT INTO _own_storehouse_data (_table, _start_t, own_entity) VALUES (currval('own_storehouse_id_seq'), current_timestamp, currval('own_entity_id_seq')); -- les doy el punto de venta por defecto; UPDATE _own_pos_document_data SET own_pos = currval('entity_id_seq') ; ALTER TABLE own_document ADD COLUMN net_total numeric(12,4); ALTER TABLE own_document ADD COLUMN tax_total numeric(12,4); ALTER TABLE alien_document ADD COLUMN net_total numeric(12,4); ALTER TABLE alien_document ADD COLUMN tax_total numeric(12,4); ALTER TABLE own_document ADD COLUMN due_date timestamp with time zone; ALTER TABLE alien_document ADD COLUMN due_date timestamp with time zone; -- en 0.1.9, había estas cosas? CREATE TABLE relation_types (id serial primary key); CREATE TABLE _relation_types_data (id bigserial primary key, entity_relation int not null references entity_relation, relation_type int not null references relation_type, _start_t timestamp not null, _end_t timestamp, _table int not null references relation_types); -- en 0.1.9 no se usaban las relations INSERT INTO relation_type VALUES (1); INSERT INTO _relation_type_data ("_start_t","_end_t","name",_table) VALUES (current_timestamp,NULL,'branch_of_organization',1); INSERT INTO relation_type VALUES (2); INSERT INTO _relation_type_data ("_start_t","_end_t","name",_table) VALUES (current_timestamp,NULL,'pos_of_branch',2); INSERT INTO relation_type VALUES (3); INSERT INTO _relation_type_data ("_start_t","_end_t","name",_table) VALUES (current_timestamp,NULL,'storehouse_of_branch',3); INSERT INTO relation_type VALUES (4); INSERT INTO _relation_type_data ("_start_t","_end_t","name",_table) VALUES (current_timestamp,NULL,'pos_of_storehouse',4); -- ni entity_type tenía parent ALTER TABLE _entity_type_data ADD COLUMN parent bigint REFERENCES entity_type; EOF RES=$( $DB -c "SELECT setval('entity_type_id_seq', max(id)) FROM entity_type;" ) if [ "$RES" != "10" ]; then cat <