/*==============================================================*/
/* Upgrade struktury z wersji 62 do 63                          */
/*==============================================================*/

/* Nowa tablica Country */
create table Country (
CountryId               INTEGER             PRIMARY KEY AUTOINCREMENT,
   IsActive             smallint            not null,
   Name                 text(60)            not null,
   Code                 text(10)            not null,
   CurrencyId           int                 not null,
   ExternalId           text(20)            null,
   Creation             datetime            not null,
   LastUpdate           datetime            not null
)
GO

/* Nowe pola w Customer, w tym jedno z referencją do tablicy Country */
ALTER TABLE Customer ADD COLUMN PostalName  text(120) null
GO
ALTER TABLE Customer ADD COLUMN ApartmentNo text(10)  null
GO
ALTER TABLE Customer ADD COLUMN CountryId   int       null
GO
ALTER TABLE Customer ADD COLUMN Wojewodztwo text(30)  null
GO
ALTER TABLE Customer ADD COLUMN Powiat      text(30)  null
GO
ALTER TABLE Customer ADD COLUMN Gmina       text(30)  null
GO
ALTER TABLE Customer ADD COLUMN USCode      text(20)  null
GO

/* Do tej pory House istniały, ale były nullowe - też je czyszczę*/
UPDATE Customer SET 
    PostalName = Town,
	House = '',
	ApartmentNo = '',
	CountryId = null,
	Wojewodztwo = '',
    Powiat = '',
	Gmina = '',
	USCode = ''
GO

/* Update numeru struktury */
UPDATE StructureVersion SET Version = 63
GO
