fix db migration

This commit is contained in:
Peter Hormanns 2013-04-30 12:03:19 +02:00
parent 2df73cbc61
commit 8d2214d123
9 changed files with 59 additions and 277 deletions

View File

@ -85,12 +85,6 @@ INSERT INTO bank_account (bp_id, autodebit_ga, autodebit_ar, autodebit_op,
bank_customer, bank_account, bank_code, bank_name) bank_customer, bank_account, bank_code, bank_name)
SELECT bp_id, false, false, false, '', '', '', '' FROM business_partner WHERE member_id=10000; SELECT bp_id, false, false, false, '', '', '', '' FROM business_partner WHERE member_id=10000;
--
-- table: billdata
--
INSERT INTO billdata (bp_id)
SELECT bp_id FROM business_partner WHERE member_id=10000;
-- --
-- Table: inet_addr -- Table: inet_addr
-- --

View File

@ -26,11 +26,43 @@ ALTER TABLE bank_account ALTER COLUMN autodebit_ga SET NOT NULL;
UPDATE bank_account SET autodebit_op = false WHERE autodebit_op IS NULL; UPDATE bank_account SET autodebit_op = false WHERE autodebit_op IS NULL;
ALTER TABLE bank_account ALTER COLUMN autodebit_op SET NOT NULL; ALTER TABLE bank_account ALTER COLUMN autodebit_op SET NOT NULL;
ALTER TABLE basepacket ADD COLUMN article_number integer NOT NULL DEFAULT 1; ALTER TABLE business_partner ADD COLUMN free boolean NOT NULL DEFAULT false;
ALTER TABLE business_partner ADD COLUMN indicator_vat character varying(20) NOT NULL DEFAULT 'GROSS';
ALTER TABLE business_partner ADD COLUMN exempt_vat boolean NOT NULL DEFAULT false;
ALTER TABLE business_partner ADD UNIQUE(bp_id);
DROP TABLE billdata CASCADE;
ALTER TABLE basepacket ADD COLUMN article_number integer NOT NULL DEFAULT 0;
ALTER TABLE basepacket ALTER COLUMN article_number DROP DEFAULT; ALTER TABLE basepacket ALTER COLUMN article_number DROP DEFAULT;
ALTER TABLE component ADD COLUMN article_number integer NOT NULL DEFAULT 1; ALTER TABLE component ADD COLUMN article_number integer NOT NULL DEFAULT 0;
ALTER TABLE component ALTER COLUMN article_number DROP DEFAULT; ALTER TABLE component ALTER COLUMN article_number DROP DEFAULT;
ALTER TABLE component DROP CONSTRAINT ckt_component;
ALTER TABLE component
ADD CONSTRAINT ckt_component CHECK (
(0 <= min_quantity) AND
(min_quantity <= default_quantity) AND
(default_quantity <= max_quantity) AND
(include_quantity <= default_quantity) AND
(0 <= include_quantity) AND
(mod(min_quantity, increment_quantity) = 0) AND
(mod(max_quantity, increment_quantity) = 0) AND
(mod(default_quantity, increment_quantity) = 0) AND
(mod(include_quantity, increment_quantity) = 0)
);
ALTER TABLE packet DROP COLUMN order_number;
ALTER TABLE packet DROP COLUMN webserver_group;
ALTER TABLE packet ADD COLUMN free boolean NOT NULL DEFAULT false;
ALTER TABLE domain DROP COLUMN domain_status;
ALTER TABLE domain DROP COLUMN domain_status_changed;
ALTER TABLE domain DROP COLUMN domain_filed;
ALTER TABLE domain DROP COLUMN domain_until;
ALTER TABLE domain DROP COLUMN domain_reminder;
ALTER TABLE domain DROP COLUMN domain_free;
ALTER TABLE domain DROP COLUMN domain_template;
CREATE TABLE price_list ( CREATE TABLE price_list (
id serial PRIMARY KEY, id serial PRIMARY KEY,
@ -43,7 +75,8 @@ CREATE TABLE customer_price_list_mapping (
price_list integer REFERENCES price_list(id), price_list integer REFERENCES price_list(id),
PRIMARY KEY (customer, price_list) PRIMARY KEY (customer, price_list)
); );
INSERT INTO customer_price_list_mapping (SELECT bp_id, 1 FROM business_partner); INSERT INTO customer_price_list_mapping
(SELECT bp_id, (SELECT id FROM price_list WHERE name LIKE 'Default%') FROM business_partner);
CREATE TABLE price ( CREATE TABLE price (
id serial PRIMARY KEY, id serial PRIMARY KEY,
@ -52,5 +85,6 @@ CREATE TABLE price (
vat decimal(4,2) NOT NULL, vat decimal(4,2) NOT NULL,
price_list integer REFERENCES price_list(id) price_list integer REFERENCES price_list(id)
); );
INSERT INTO price VALUES (1, 0, 0, 0, 1); INSERT INTO price (article_number, price, vat, price_list)
VALUES (0, 0, 0, (SELECT id FROM price_list WHERE name LIKE 'Default%'));

View File

@ -3,8 +3,6 @@ DROP TABLE price ;
DROP TABLE price_list ; DROP TABLE price_list ;
DROP TABLE bank_account ; DROP TABLE bank_account ;
DROP SEQUENCE bank_account_bank_account_id_seq ; DROP SEQUENCE bank_account_bank_account_id_seq ;
DROP TABLE billdata ;
DROP SEQUENCE billdata_billdata_id_seq ;
DROP TABLE contact ; DROP TABLE contact ;
DROP SEQUENCE contact_contact_id_seq ; DROP SEQUENCE contact_contact_id_seq ;
DROP TABLE database ; DROP TABLE database ;

View File

@ -5,13 +5,14 @@
CREATE TABLE bank_account ( CREATE TABLE bank_account (
bank_account_id integer DEFAULT nextval(('"bank_account_bank_account_id_seq"'::text)::regclass) NOT NULL, bank_account_id integer DEFAULT nextval(('"bank_account_bank_account_id_seq"'::text)::regclass) NOT NULL,
bp_id integer NOT NULL, bp_id integer NOT NULL,
autodebit_ga boolean NOT NULL DEFAULT false, autodebit_ga boolean NOT NULL,
autodebit_ar boolean NOT NULL DEFAULT false, autodebit_ar boolean NOT NULL,
autodebit_op boolean NOT NULL DEFAULT false, autodebit_op boolean NOT NULL,
bank_customer character varying(50) NOT NULL DEFAULT '', bank_customer character varying(50),
bank_account character varying(10) NOT NULL DEFAULT '', bank_account character varying(10),
bank_code character varying(8) NOT NULL DEFAULT '', bank_code character varying(8),
bank_name character varying(50) NOT NULL DEFAULT '' bank_name character varying(50),
CONSTRAINT ckt_bank_account CHECK (((((((bank_customer IS NOT NULL) AND (bank_account IS NOT NULL)) AND (bank_code IS NOT NULL)) AND (bank_name IS NOT NULL)) AND (((autodebit_ga = true) OR (autodebit_ar = true)) OR (autodebit_op = true))) OR (((autodebit_ga = false) AND (autodebit_ar = false)) AND (autodebit_op = false))))
); );
@ -75,35 +76,6 @@ CREATE SEQUENCE basepacket_basepacket_id_seq
CACHE 1; CACHE 1;
--
-- Name: billdata; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
CREATE TABLE billdata (
billdata_id integer DEFAULT nextval(('"billdata_billdata_id_seq"'::text)::regclass) NOT NULL,
bp_id integer NOT NULL,
tariff_domain_discount_since date,
tariff_domain_discount_until date,
tariff_traffic_discount_since date,
tariff_traffic_discount_until date,
tariff_quota_discount_since date,
tariff_quota_discount_until date,
tariff_discount_since date,
tariff_discount_until date
);
--
-- Name: billdata_billdata_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE billdata_billdata_id_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
-- --
-- Name: business_partner; Type: TABLE; Schema: public; Owner: -; Tablespace: -- Name: business_partner; Type: TABLE; Schema: public; Owner: -; Tablespace:
-- --
@ -156,10 +128,12 @@ CREATE TABLE component (
include_quantity integer NOT NULL, include_quantity integer NOT NULL,
admin_only boolean NOT NULL, admin_only boolean NOT NULL,
CONSTRAINT ckt_component CHECK ( CONSTRAINT ckt_component CHECK (
(min_quantity <= max_quantity) AND (0 <= min_quantity) AND
(min_quantity <= default_quantity) AND (min_quantity <= default_quantity) AND
(default_quantity <= max_quantity) AND (default_quantity <= max_quantity) AND
(include_quantity <= max_quantity) AND (include_quantity <= default_quantity) AND
(0 <= include_quantity) AND
(mod(min_quantity, increment_quantity) = 0) AND
(mod(max_quantity, increment_quantity) = 0) AND (mod(max_quantity, increment_quantity) = 0) AND
(mod(default_quantity, increment_quantity) = 0) AND (mod(default_quantity, increment_quantity) = 0) AND
(mod(include_quantity, increment_quantity) = 0) (mod(include_quantity, increment_quantity) = 0)
@ -562,14 +536,6 @@ ALTER TABLE ONLY basepacket
ADD CONSTRAINT pk_basepacket PRIMARY KEY (basepacket_id); ADD CONSTRAINT pk_basepacket PRIMARY KEY (basepacket_id);
--
-- Name: pk_billdata; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
ALTER TABLE ONLY billdata
ADD CONSTRAINT pk_billdata PRIMARY KEY (billdata_id);
-- --
-- Name: pk_business_partner; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- Name: pk_business_partner; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
-- --
@ -679,13 +645,6 @@ CREATE UNIQUE INDEX basecomponent_in_1 ON basecomponent USING btree (basecompone
CREATE UNIQUE INDEX basepacket_in_1 ON basepacket USING btree (basepacket_code); CREATE UNIQUE INDEX basepacket_in_1 ON basepacket USING btree (basepacket_code);
--
-- Name: billdata_in_1; Type: INDEX; Schema: public; Owner: -; Tablespace:
--
CREATE UNIQUE INDEX billdata_in_1 ON billdata USING btree (bp_id);
-- --
-- Name: component_in_1; Type: INDEX; Schema: public; Owner: -; Tablespace: -- Name: component_in_1; Type: INDEX; Schema: public; Owner: -; Tablespace:
-- --
@ -855,14 +814,6 @@ ALTER TABLE ONLY component
ADD CONSTRAINT fk_bcomp_bpack FOREIGN KEY (basepacket_id) REFERENCES basepacket(basepacket_id) ON UPDATE RESTRICT ON DELETE RESTRICT; ADD CONSTRAINT fk_bcomp_bpack FOREIGN KEY (basepacket_id) REFERENCES basepacket(basepacket_id) ON UPDATE RESTRICT ON DELETE RESTRICT;
--
-- Name: fk_billdata_reference_business; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY billdata
ADD CONSTRAINT fk_billdata_reference_business FOREIGN KEY (bp_id) REFERENCES business_partner(bp_id) ON UPDATE RESTRICT ON DELETE RESTRICT;
-- --
-- Name: fk_comp_bcomp; Type: FK CONSTRAINT; Schema: public; Owner: - -- Name: fk_comp_bcomp; Type: FK CONSTRAINT; Schema: public; Owner: -
-- --

View File

@ -41,17 +41,17 @@ public class BankAccount extends AbstractEntity implements Serializable {
@Column(name = "autodebit_op", columnDefinition = "boolean", nullable = false) @Column(name = "autodebit_op", columnDefinition = "boolean", nullable = false)
private Boolean autoDebitOP = Boolean.FALSE; private Boolean autoDebitOP = Boolean.FALSE;
@Column(name = "bank_customer", columnDefinition = "character varying(50)", nullable = false) @Column(name = "bank_customer", columnDefinition = "character varying(50)")
private String bankCustomer = ""; private String bankCustomer;
@Column(name = "bank_account", columnDefinition = "character varying(10)", nullable = false) @Column(name = "bank_account", columnDefinition = "character varying(10)")
private String bankAccount = ""; private String bankAccount;
@Column(name = "bank_code", columnDefinition = "character varying(8)", nullable = false) @Column(name = "bank_code", columnDefinition = "character varying(8)")
private String bankCode = ""; private String bankCode;
@Column(name = "bank_name", columnDefinition = "character varying(50)", nullable = false) @Column(name = "bank_name", columnDefinition = "character varying(50)")
private String bankName = ""; private String bankName;
public static String createQueryFromStringKey(String humanKey) { public static String createQueryFromStringKey(String humanKey) {
return "customer.name = " + humanKey; return "customer.name = " + humanKey;

View File

@ -96,9 +96,6 @@ public class Customer extends AbstractEntity implements Serializable {
@OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer") @OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer")
private BankAccount bankAccount; private BankAccount bankAccount;
@OneToOne(fetch = EAGER, cascade = ALL, mappedBy = "customer")
private CustomersTariff billData;
@OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "customer") @OneToMany(fetch = LAZY, cascade = ALL, mappedBy = "customer")
@OrderBy("name") @OrderBy("name")
private Set<Pac> pacs; private Set<Pac> pacs;
@ -244,14 +241,6 @@ public class Customer extends AbstractEntity implements Serializable {
this.bankAccount = bankAccount; this.bankAccount = bankAccount;
} }
public CustomersTariff getBillData() {
return billData;
}
public void setBillData(CustomersTariff tariff) {
this.billData = tariff;
}
public Set<Pac> getPacs() { public Set<Pac> getPacs() {
return pacs; return pacs;
} }

View File

@ -37,11 +37,6 @@ public class CustomerModuleImpl extends AbstractModuleImpl {
bankAccount.setCustomer(newCustomer); bankAccount.setCustomer(newCustomer);
newCustomer.setBankAccount(bankAccount); newCustomer.setBankAccount(bankAccount);
} }
CustomersTariff billData = newCustomer.getBillData();
if (billData == null) {
billData = new CustomersTariff(newCustomer);
newCustomer.setBillData(billData);
}
GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction()); GenericModuleImpl helperModule = new GenericModuleImpl(getTransaction());
UnixUser custAccount = new UnixUser(); UnixUser custAccount = new UnixUser();
custAccount.setComment(TextUtil.replaceUmlautCharacters(custComment)); custAccount.setComment(TextUtil.replaceUmlautCharacters(custComment));

View File

@ -1,179 +0,0 @@
package de.hsadmin.mods.cust;
import static javax.persistence.FetchType.EAGER;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.mods.user.UnixUser;
@Entity(name = "CustomersTariffs")
@Table(name = "billdata")
public class CustomersTariff extends AbstractEntity implements Serializable {
private static final long serialVersionUID = -3628577459027111705L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "billdata_id", columnDefinition = "integer")
private long id;
@JoinColumn(name = "bp_id", columnDefinition = "integer")
@OneToOne(fetch = EAGER)
private Customer customer;
@Column(name = "tariff_domain_discount_since", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date domainDiscountSince;
@Column(name = "tariff_domain_discount_until", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date domainDiscountUntil;
@Column(name = "tariff_traffic_discount_since", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date trafficDiscountSince;
@Column(name = "tariff_traffic_discount_until", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date trafficDiscountUntil;
@Column(name = "tariff_quota_discount_since", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date quotaDiscountSince;
@Column(name = "tariff_quota_discount_until", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date quotaDiscountUntil;
@Column(name = "tariff_discount_since", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date discountSince;
@Column(name = "tariff_discount_until", columnDefinition = "date")
@Temporal(javax.persistence.TemporalType.DATE)
private Date discountUntil;
public CustomersTariff() {
}
public CustomersTariff(Customer cust) {
this.customer = cust;
}
public static String createQueryFromStringKey(String humanKey) {
return "customer.name = '" + humanKey + "'";
}
@Override
public String createStringKey() {
return getCustomer().getName();
}
@Override
public long id() {
return id;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public Date getDomainDiscountSince() {
return domainDiscountSince;
}
public void setDomainDiscountSince(Date domainDiscountSince) {
this.domainDiscountSince = domainDiscountSince;
}
public Date getDomainDiscountUntil() {
return domainDiscountUntil;
}
public void setDomainDiscountUntil(Date domainDiscountUntil) {
this.domainDiscountUntil = domainDiscountUntil;
}
public Date getTrafficDiscountSince() {
return trafficDiscountSince;
}
public void setTrafficDiscountSince(Date trafficDiscountSince) {
this.trafficDiscountSince = trafficDiscountSince;
}
public Date getTrafficDiscountUntil() {
return trafficDiscountUntil;
}
public void setTrafficDiscountUntil(Date trafficDiscountUntil) {
this.trafficDiscountUntil = trafficDiscountUntil;
}
public Date getQuotaDiscountSince() {
return quotaDiscountSince;
}
public void setQuotaDiscountSince(Date quotaDiscountSince) {
this.quotaDiscountSince = quotaDiscountSince;
}
public Date getQuotaDiscountUntil() {
return quotaDiscountUntil;
}
public void setQuotaDiscountUntil(Date quotaDiscountUntil) {
this.quotaDiscountUntil = quotaDiscountUntil;
}
public Date getDiscountSince() {
return discountSince;
}
public void setDiscountSince(Date discountSince) {
this.discountSince = discountSince;
}
public Date getDiscountUntil() {
return discountUntil;
}
public void setDiscountUntil(Date discountUntil) {
this.discountUntil = discountUntil;
}
@Override
public boolean isNew() {
return id == 0;
}
@Override
public UnixUser owningUser(EntityManager em) {
return customer.owningUser(em);
}
}

View File

@ -24,7 +24,7 @@ public class DomainOptionValues extends DefaultSelectableValues {
list.add(new BooleanListValue("includes")); list.add(new BooleanListValue("includes"));
list.add(new BooleanListValue("indexes")); list.add(new BooleanListValue("indexes"));
list.add(new BooleanListValue("multiviews")); list.add(new BooleanListValue("multiviews"));
list.add(new BooleanListValue("php")); // list.add(new BooleanListValue("php"));
return list; return list;
} }