create table if not exists seasons(
id integer not null,
name varchar(100) not null,
active integer not null default 1,
created_at varchar(100) not null
);


create table if not exists users(
id integer not null,
name varchar(100) not null,
surname varchar(100) not null,
username varchar(100) not null,
hash varchar(100) not null,
rightsid integer not null,
active integer not null default 1,
access_code integer not null,
created_at varchar(100) not null
);



create table if not exists growers(
id integer primary key autoIncrement,
userid integer not null,
name varchar(100) not null,
surname varchar(100) not null,
grower_num varchar(100),
area varchar(100) not null,
province varchar(100),
phone varchar(100),
id_num varchar(100) not null,
seasonid integer not null,
sync integer not null default 0,
created_at varchar(100),
foreign key(userid) references users(id),
foreign key(seasonid) references seasons(id)
);


create table if not exists grower_number_of_bales(
id integer not null,
userid integer not null,
seasonid integer not null,
growerid integer not null,
bales integer not null,
sync integer not null default 0,
surrogate integer not null default 0,
created_at varchar(100) not null,
foreign key(userid) references users(id),
foreign key(seasonid) references seasons(id),
foreign key(growerid) references growers(id)
);



create table if not exists bale_tags(
id integer not null,
userid integer not null,
seasonid integer not null,
grower_number_of_balesid integer not null,
code varchar(100) not null,
company_tag varchar(100) ,
sync integer not null default 0,
used integer not null default 0,
booked integer not null default 0,
sync integer not null default 0,
created_at varchar(100) not null,
foreign key(userid) references users(id),
foreign key(seasonid) references seasons(id),
foreign key(grower_number_of_balesid) references grower_number_of_bales(id)
);