drop table if exists access_tokens;
drop table if exists accounts;
drop table if exists linked_accounts;
drop table if exists refresh_tokens;
drop table if exists type_salad_boolean_types;
drop table if exists type_salad_character_types;
drop table if exists type_salad_numeric_arbitrary_precision_types;
drop table if exists type_salad_numeric_floating_point_types;
drop table if exists type_salad_numeric_integer_types;
drop table if exists type_salad_numeric_serial_types;
drop table if exists type_salad_uuid_types;

create table access_tokens (
	id uuid not null primary key default gen_random_uuid(),
	name varchar(50),
	description varchar(4000),
	expires_at timestamp with time zone,
    expires_in interval,

	created_at timestamp with time zone not null,
	created_by_account_id uuid,
	deleted_at timestamp with time zone,
	deleted_by_account_id uuid,
	updated_at timestamp with time zone,
	updated_by_account_id uuid,
	owner_account_id uuid
);

create table accounts (
	id uuid not null primary key default gen_random_uuid(),
	name varchar(50),
	email varchar(255),
	metadata json,

	created_at timestamp with time zone not null,
	created_by_account_id uuid,
	deleted_at timestamp with time zone,
	deleted_by_account_id uuid,
	updated_at timestamp with time zone,
	updated_by_account_id uuid,
	owner_account_id uuid
);

create table linked_accounts (
	id uuid not null primary key default gen_random_uuid(),
	type varchar(25) not null,
	provider varchar(25) not null,
	provider_uid varchar(50),
	metadata json,
	
	created_at timestamp with time zone not null,
	created_by_account_id uuid,
	deleted_at timestamp with time zone,
	deleted_by_account_id uuid,
	updated_at timestamp with time zone,
	updated_by_account_id uuid,
	owner_account_id uuid
);

create table refresh_tokens (
	id uuid not null primary key default gen_random_uuid()
);

create table type_salad_boolean_types (
	col_1 boolean
);

create table type_salad_character_types (
	col_1 character varying(25),
	col_2 varchar(25),
	col_3 bpchar,
	col_4 text
);

create table type_salad_numeric_arbitrary_precision_types (
	id varchar(36) not null primary key,
	col_2 numeric,
	col_3 numeric(3),
	col_4 numeric(3, 1)
);

create table type_salad_numeric_floating_point_types (
	id varchar(36) not null primary key,
	col_2 real,
	col_3 double precision
);

create table type_salad_numeric_integer_types (
	id varchar(36) not null primary key,
	col_2 smallint,
	col_3 integer,
	col_4 bigint
);

create table type_salad_numeric_serial_types (
	id varchar(36) not null primary key,
	col_2 smallserial,
	col_3 serial,
	col_4 bigserial
);

create table type_salad_uuid_types (
	id uuid not null primary key default gen_random_uuid()
);

alter table linked_accounts
add constraint fk_linked_accounts_account
foreign key (owner_account_id) references accounts (id);
