Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(alerts): add kali / legi alerts (#24)
Co-authored-by: Douglas Duteil <douglasduteil@gmail.com>
- Loading branch information
1 parent
0d8b336
commit c8c5f1a
Showing
28 changed files
with
1,471 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
*.md | ||
**/node_modules | ||
**/.next/cache | ||
data/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
*.DS_Store | ||
node_modules | ||
.env.production | ||
data/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM hasura/graphql-engine:v1.2.1.cli-migrations-v2 | ||
FROM hasura/graphql-engine:v1.2.2.cli-migrations-v2 | ||
ENV HASURA_GRAPHQL_ENABLE_TELEMETRY false | ||
COPY ./migrations /hasura-migrations | ||
COPY ./metadata /hasura-metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
DROP TABLE "public"."alerts"; | ||
|
||
DROP TABLE "public"."sources"; | ||
|
||
DROP TABLE "public"."alert_status"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
|
||
CREATE TABLE "public"."alert_status"("name" text NOT NULL DEFAULT 'new', PRIMARY KEY ("name") ); | ||
COMMENT ON TABLE "public"."alert_status" IS E'alert statuses'; | ||
|
||
INSERT INTO public.alert_status (name) VALUES ('todo'); | ||
INSERT INTO public.alert_status (name) VALUES ('doing'); | ||
INSERT INTO public.alert_status (name) VALUES ('done'); | ||
INSERT INTO public.alert_status (name) VALUES ('rejected'); | ||
|
||
CREATE TABLE "public"."sources"( | ||
"repository" text NOT NULL, | ||
"label" text NOT NULL, | ||
"tag" text NOT NULL, | ||
"created_at" timestamptz NOT NULL DEFAULT now(), | ||
PRIMARY KEY ("repository") | ||
); | ||
|
||
COMMENT ON TABLE "public"."sources" IS E'sources are git repository that acts as data sources to track changes'; | ||
|
||
INSERT INTO public.sources (repository, label, tag) VALUES ('socialgouv/legi-data', 'code du travail', 'v1.12.0'); | ||
INSERT INTO public.sources (repository, label, tag) VALUES ('socialgouv/kali-data', 'conventions collectives', 'v1.64.0'); | ||
|
||
CREATE TABLE "public"."alerts"( | ||
"id" uuid NOT NULL DEFAULT gen_random_uuid(), | ||
"info" jsonb NOT NULL, | ||
"status" text NOT NULL DEFAULT 'todo', | ||
"repository" text NOT NULL, | ||
"ref" text NOT NULL, | ||
"changes" jsonb NOT NULL, | ||
"created_at" timestamptz NULL DEFAULT now(), | ||
"updated_at" timestamptz NULL DEFAULT now(), | ||
PRIMARY KEY ("id") , | ||
FOREIGN KEY ("status") REFERENCES "public"."alert_status"("name") ON UPDATE restrict ON DELETE restrict, | ||
FOREIGN KEY ("repository") REFERENCES "public"."sources"("repository") ON UPDATE restrict ON DELETE cascade); | ||
|
||
COMMENT ON TABLE "public"."alerts" IS | ||
E'alerts reprensent a change in a text from a source'; | ||
|
||
CREATE TRIGGER "set_public_alerts_updated_at" | ||
BEFORE UPDATE ON public.alerts | ||
FOR EACH ROW | ||
EXECUTE PROCEDURE trigger_set_timestamp(); | ||
|
||
COMMENT ON TRIGGER "set_public_alerts_updated_at" ON public.alerts | ||
IS 'trigger to set value of column "updated_at" to current timestamp on row update'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { promises: fs } = require("fs"); | ||
const path = require("path"); | ||
const filename = | ||
process.env.DUMP_FILE || path.join(__dirname, "..", "data", "dump.json"); | ||
const { updateSource, insertAlert } = require("./update-alerts"); | ||
|
||
async function main() { | ||
console.log(filename); | ||
const fileContent = await fs.readFile(filename); | ||
const data = JSON.parse(fileContent); | ||
|
||
for (const result of data) { | ||
if (result.changes.length === 0) { | ||
console.log(`no update for ${result.repository}`); | ||
continue; | ||
} | ||
const inserts = await Promise.all( | ||
result.changes.map((diff) => insertAlert(result.repository, diff)) | ||
); | ||
inserts.forEach((insert) => { | ||
const { ref, repository, info } = insert.returning[0]; | ||
console.log(`insert alert for ${ref} on ${repository} (${info.file})`); | ||
}); | ||
console.log(`create ${inserts.length} alert for ${result.repository}`); | ||
const update = await updateSource(result.repository, result.newRef); | ||
console.log(`update source ${update.repository} to ${update.tag}`); | ||
} | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const ccns = [ | ||
{ id: "KALICONT000005635624", num: 16 }, | ||
{ id: "KALICONT000005635234", num: 29 }, | ||
{ id: "KALICONT000005635613", num: 44 }, | ||
{ id: "KALICONT000005635630", num: 86 }, | ||
{ id: "KALICONT000005635184", num: 176 }, | ||
{ id: "KALICONT000005635872", num: 275 }, | ||
{ id: "KALICONT000005635856", num: 292 }, | ||
{ id: "KALICONT000005635407", num: 413 }, | ||
{ id: "KALICONT000005635373", num: 573 }, | ||
{ id: "KALICONT000005635842", num: 650 }, | ||
{ id: "KALICONT000005635617", num: 675 }, | ||
{ id: "KALICONT000005635826", num: 787 }, | ||
{ id: "KALICONT000005635886", num: 843 }, | ||
{ id: "KALICONT000005635953", num: 1043 }, | ||
{ id: "KALICONT000005635191", num: 1090 }, | ||
{ id: "KALICONT000005635409", num: 1147 }, | ||
{ id: "KALICONT000005635418", num: 1266 }, | ||
{ id: "KALICONT000005635405", num: 1351 }, | ||
{ id: "KALICONT000005635653", num: 1404 }, | ||
{ id: "KALICONT000005635444", num: 1480 }, | ||
{ id: "KALICONT000005635594", num: 1483 }, | ||
{ id: "KALICONT000005635173", num: 1486 }, | ||
{ id: "KALICONT000005635596", num: 1501 }, | ||
{ id: "KALICONT000005635421", num: 1505 }, | ||
{ id: "KALICONT000005635435", num: 1516 }, | ||
{ id: "KALICONT000005635870", num: 1517 }, | ||
{ id: "KALICONT000005635177", num: 1518 }, | ||
{ id: "KALICONT000005635413", num: 1527 }, | ||
{ id: "KALICONT000005635221", num: 1596 }, | ||
{ id: "KALICONT000005635220", num: 1597 }, | ||
{ id: "KALICONT000005635871", num: 1606 }, | ||
{ id: "KALICONT000005635918", num: 1672 }, | ||
{ id: "KALICONT000005635467", num: 1702 }, | ||
{ id: "KALICONT000005635685", num: 1740 }, | ||
{ id: "KALICONT000005635534", num: 1979 }, | ||
{ id: "KALICONT000005635528", num: 1996 }, | ||
{ id: "KALICONT000005635550", num: 2098 }, | ||
{ id: "KALICONT000005635792", num: 2111 }, | ||
{ id: "KALICONT000005635780", num: 2120 }, | ||
{ id: "KALICONT000005635557", num: 2148 }, | ||
{ id: "KALICONT000005635085", num: 2216 }, | ||
{ id: "KALICONT000005635813", num: 2264 }, | ||
{ id: "KALICONT000005635807", num: 2395 }, | ||
{ id: "KALICONT000017941839", num: 2420 }, | ||
{ id: "KALICONT000017577652", num: 2511 }, | ||
{ id: "KALICONT000018563755", num: 2596 }, | ||
{ id: "KALICONT000018773893", num: 2609 }, | ||
{ id: "KALICONT000018926209", num: 2614 }, | ||
{ id: "KALICONT000025805800", num: 2941 }, | ||
{ id: "KALICONT000027172335", num: 3043 }, | ||
{ id: "KALICONT000027084096", num: 3127 }, | ||
]; | ||
|
||
module.exports = { ccns }; |
Oops, something went wrong.