12_cria_tabelas_modulo_avaliacao.sql
3.55 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
-- //
--
-- Cria as tabelas para o módulo Avaliação.
--
-- @author Eriksen Costa Paixão <eriksen.paixao_bs@cobra.com.br>
-- @license @@license@@
-- @version $Id$
--
CREATE TABLE "modules"."falta_aluno" (
"id" serial NOT NULL,
"matricula_id" int NOT NULL,
"tipo_falta" smallint NOT NULL,
PRIMARY KEY("id")
);
CREATE TABLE "modules"."falta_componente_curricular" (
"id" serial NOT NULL,
"falta_aluno_id" int NOT NULL,
"componente_curricular_id" int NOT NULL,
"quantidade" int NULL DEFAULT 0,
"etapa" varchar(2) NOT NULL,
PRIMARY KEY("falta_aluno_id","componente_curricular_id")
);
CREATE TABLE "modules"."falta_geral" (
"id" serial NOT NULL,
"falta_aluno_id" int NOT NULL,
"quantidade" int NULL DEFAULT 0,
"etapa" varchar(2) NOT NULL,
PRIMARY KEY("falta_aluno_id")
);
CREATE TABLE "modules"."nota_aluno" (
"id" serial NOT NULL,
"matricula_id" int NOT NULL,
PRIMARY KEY("id")
);
CREATE TABLE "modules"."nota_componente_curricular" (
"id" serial NOT NULL,
"nota_aluno_id" int NOT NULL,
"componente_curricular_id" int NOT NULL,
"nota" decimal(5,3) NULL DEFAULT 0,
"nota_arredondada" varchar(5) NULL DEFAULT 0,
"etapa" varchar(2) NOT NULL,
PRIMARY KEY("id")
);
CREATE TABLE "modules"."nota_componente_curricular_media" (
"nota_aluno_id" int NOT NULL,
"componente_curricular_id" int NOT NULL,
"media" decimal(5,3) NULL DEFAULT 0,
"media_arredondada" varchar(5) NULL DEFAULT 0,
PRIMARY KEY("nota_aluno_id","componente_curricular_id")
);
ALTER TABLE "modules"."falta_componente_curricular"
ADD CONSTRAINT "falta_componente_curricular_falta_aluno_fk"
FOREIGN KEY("falta_aluno_id")
REFERENCES "modules"."falta_aluno"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION ;
ALTER TABLE "modules"."falta_geral"
ADD CONSTRAINT "falta_geral_falta_aluno_fk"
FOREIGN KEY("falta_aluno_id")
REFERENCES "modules"."falta_aluno"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION ;
ALTER TABLE "modules"."nota_componente_curricular"
ADD CONSTRAINT "nota_componente_curricular_nota_aluno_fk"
FOREIGN KEY("nota_aluno_id")
REFERENCES "modules"."nota_aluno"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION ;
ALTER TABLE "modules"."nota_componente_curricular_media"
ADD CONSTRAINT "nota_componente_curricular_media_nota_aluno_fk"
FOREIGN KEY("nota_aluno_id")
REFERENCES "modules"."nota_aluno"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION ;
CREATE UNIQUE INDEX "nota_componente_curricular_media_nota_aluno_key"
ON "modules"."nota_componente_curricular_media"("nota_aluno_id");
-- //@UNDO
DROP INDEX "nota_componente_curricular_media_nota_aluno_key";
ALTER TABLE "modules"."falta_componente_curricular"
DROP CONSTRAINT "falta_componente_curricular_falta_aluno_fk" CASCADE ;
ALTER TABLE "modules"."falta_geral"
DROP CONSTRAINT "falta_geral_falta_aluno_fk" CASCADE ;
ALTER TABLE "modules"."nota_componente_curricular"
DROP CONSTRAINT "nota_componente_curricular_nota_aluno_fk" CASCADE ;
ALTER TABLE "modules"."nota_componente_curricular_media"
DROP CONSTRAINT "nota_componente_curricular_media_nota_aluno_fk" CASCADE ;
DROP TABLE "modules"."falta_aluno";
DROP TABLE "modules"."falta_componente_curricular";
DROP TABLE "modules"."falta_geral";
DROP TABLE "modules"."nota_aluno";
DROP TABLE "modules"."nota_componente_curricular";
DROP TABLE "modules"."nota_componente_curricular_media";
-- //