-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtabelas.sql
More file actions
135 lines (125 loc) · 4.73 KB
/
tabelas.sql
File metadata and controls
135 lines (125 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
-- =====================================================
-- TURISTEI - CORE DATABASE STRUCTURE
-- Marketplace multi-fornecedor (backend em Supabase)
-- =====================================================
-- ====================================
-- Tabela de Prestadores de Serviço
-- ====================================
CREATE TABLE prestadores (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
user_id uuid NOT NULL REFERENCES auth.users(id) ON DELETE RESTRICT,
nome text NOT NULL,
email text,
telefone text,
comissao_override_percent numeric(5,2),
ativo boolean DEFAULT true,
created_at timestamptz DEFAULT now()
);
-- ====================================
-- Tabela de Serviços por Prestador
-- ====================================
CREATE TABLE servicos (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
prestador_id uuid NOT NULL REFERENCES prestadores(id) ON DELETE RESTRICT,
titulo text NOT NULL,
descricao text,
preco numeric(12,2) NOT NULL,
ativo boolean DEFAULT true,
created_at timestamptz DEFAULT now()
);
-- ====================================
-- Tabela de Mídias dos Serviços
-- ====================================
CREATE TABLE servicos_midias (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
servico_id uuid NOT NULL REFERENCES servicos(id) ON DELETE RESTRICT,
url text NOT NULL,
ordem integer DEFAULT 0,
created_at timestamptz DEFAULT now()
);
-- ====================================
-- Tabela de Planos da Plataforma
-- ====================================
CREATE TABLE planos (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
nome text NOT NULL,
descricao text,
limite_servicos integer,
limite_midias integer,
permite_video boolean DEFAULT false,
destaque boolean DEFAULT false,
preco_mensal numeric(12,2) NOT NULL,
ativo boolean DEFAULT true,
created_at timestamptz DEFAULT now()
);
-- ====================================
-- Tabela de Assinaturas dos Prestadores
-- ====================================
CREATE TABLE assinaturas (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
prestador_id uuid NOT NULL REFERENCES prestadores(id) ON DELETE RESTRICT,
plano_id uuid NOT NULL REFERENCES planos(id) ON DELETE RESTRICT,
status text NOT NULL,
inicio_em date NOT NULL,
fim_em date,
created_at timestamptz DEFAULT now()
);
-- ====================================
-- Tabela de Pedidos (cabeçalho)
-- ====================================
CREATE TABLE pedidos (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
turista_id uuid NOT NULL REFERENCES auth.users(id) ON DELETE RESTRICT,
valor_bruto numeric(12,2) NOT NULL DEFAULT 0,
valor_final numeric(12,2) NOT NULL DEFAULT 0,
status text NOT NULL,
created_at timestamptz DEFAULT now()
);
-- ====================================
-- Tabela de Itens do Pedido (por prestador)
-- ====================================
CREATE TABLE pedidos_itens (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
pedido_id uuid NOT NULL REFERENCES pedidos(id) ON DELETE RESTRICT,
prestador_id uuid NOT NULL REFERENCES prestadores(id) ON DELETE RESTRICT,
servico_id uuid NOT NULL REFERENCES servicos(id) ON DELETE RESTRICT,
quantidade integer NOT NULL DEFAULT 1,
preco_unitario numeric(12,2) NOT NULL,
valor_total numeric(12,2) NOT NULL,
created_at timestamptz DEFAULT now()
);
-- ====================================
-- Pagamentos dos Pedidos
-- ====================================
CREATE TABLE pagamentos_pedido (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
pedido_id uuid NOT NULL REFERENCES pedidos(id) ON DELETE RESTRICT,
valor numeric(12,2) NOT NULL,
status text NOT NULL,
metodo text,
pago_em timestamptz,
created_at timestamptz DEFAULT now()
);
-- ====================================
-- Comissões da Plataforma por Item
-- ====================================
CREATE TABLE comissoes_itens (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
pedido_item_id uuid NOT NULL REFERENCES pedidos_itens(id) ON DELETE RESTRICT,
prestador_id uuid NOT NULL REFERENCES prestadores(id) ON DELETE RESTRICT,
percentual numeric(5,2) NOT NULL,
valor numeric(12,2) NOT NULL,
created_at timestamptz DEFAULT now()
);
-- ====================================
-- Repasses Financeiros por Prestador
-- ====================================
CREATE TABLE repasses_prestador (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
pedido_id uuid NOT NULL REFERENCES pedidos(id) ON DELETE RESTRICT,
prestador_id uuid NOT NULL REFERENCES prestadores(id) ON DELETE RESTRICT,
valor_bruto numeric(12,2) NOT NULL,
comissao_plataforma_valor numeric(12,2) NOT NULL,
valor_liquido numeric(12,2) NOT NULL,
created_at timestamptz DEFAULT now()
);