From f8651a94478526852cb6307d4a0c3f12abbfaba6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andrej=20Rama=C5=A1euski?= <andrej@x2.cz>
Date: Thu, 8 Apr 2021 23:48:39 +0200
Subject: [PATCH] Pridane eventy do datoveho modelu

---
 .gitlab-ci.yml                       |  2 +-
 lib/CF/Schema/Result/Event.pm        | 46 ++++++++++++++++++++++++++++
 lib/CF/Schema/Result/EventACL.pm     | 34 ++++++++++++++++++++
 lib/CF/Schema/Result/ProgramEntry.pm |  1 +
 sql/8/up.sql                         | 28 +++++++++++++++++
 5 files changed, 110 insertions(+), 1 deletion(-)
 create mode 100644 lib/CF/Schema/Result/Event.pm
 create mode 100644 lib/CF/Schema/Result/EventACL.pm
 create mode 100644 sql/8/up.sql

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 642ed97..e93c90f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,7 +2,7 @@ image: docker:19.03.12
 
 variables:
   DOCKER_TLS_CERTDIR: "/certs"
-  IMAGE_VER: 1.11.0
+  IMAGE_VER: 1.12.0
 
 services:
   - docker:19.03.12-dind
diff --git a/lib/CF/Schema/Result/Event.pm b/lib/CF/Schema/Result/Event.pm
new file mode 100644
index 0000000..3c2799d
--- /dev/null
+++ b/lib/CF/Schema/Result/Event.pm
@@ -0,0 +1,46 @@
+package CF::Schema::Result::Event;
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+our $VERSION = 1;
+
+__PACKAGE__->table('events');
+
+__PACKAGE__->add_columns(
+    id => {
+        data_type         => 'integer',
+        is_auto_increment => 1,
+        is_nullable       => 0,
+        sequence          => 'uid_seq'
+    },
+    qw(
+        uuid
+        type
+        owner_id
+        start
+        finish
+        name
+        description
+        organizer
+        stream_url
+    ),
+);
+
+__PACKAGE__->belongs_to(
+    user => 'CF::Schema::Result::User',
+    {
+        'foreign.id' => 'self.owner_id',
+    },
+);
+
+__PACKAGE__->has_many(
+    acls => 'CF::Schema::Result::EventACL',
+    { 'foreign.event_id' => 'self.id', },
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;
diff --git a/lib/CF/Schema/Result/EventACL.pm b/lib/CF/Schema/Result/EventACL.pm
new file mode 100644
index 0000000..8dc9dcf
--- /dev/null
+++ b/lib/CF/Schema/Result/EventACL.pm
@@ -0,0 +1,34 @@
+package CF::Schema::Result::EventACL;
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+our $VERSION = 1;
+
+__PACKAGE__->table('events_acl');
+
+__PACKAGE__->add_columns(
+    id => {
+        data_type         => 'integer',
+        is_auto_increment => 1,
+        is_nullable       => 0,
+        sequence          => 'uid_seq'
+    },
+    qw(
+        event_id
+        subject_class
+        subject
+        role
+    ),
+);
+
+__PACKAGE__->belongs_to(
+    event => 'CF::Schema::Result::Event',
+    {
+        'foreign.id' => 'self.event_id',
+    },
+);
+
+1;
diff --git a/lib/CF/Schema/Result/ProgramEntry.pm b/lib/CF/Schema/Result/ProgramEntry.pm
index d1d26cb..0e0f5fd 100644
--- a/lib/CF/Schema/Result/ProgramEntry.pm
+++ b/lib/CF/Schema/Result/ProgramEntry.pm
@@ -17,6 +17,7 @@ __PACKAGE__->add_columns(
         sequence          => 'uid_seq'
     },
     qw(
+        event_id
         number
         start
         finish
diff --git a/sql/8/up.sql b/sql/8/up.sql
new file mode 100644
index 0000000..dc274ee
--- /dev/null
+++ b/sql/8/up.sql
@@ -0,0 +1,28 @@
+create table "events" (
+    "id" integer not null default nextval('uid_seq'),
+    "uuid" uuid not null, -- unique string
+    "type" smallint not null default 1, --1
+    "owner_id" integer not null,
+    "start" timestamp(0),
+    "finish" timestamp(0),
+    "name" text not null,
+    "description" text,
+    "organizer" text,
+    "stream_url" text, -- externi stream
+    primary key("id"),
+    unique("uuid"),
+    foreign key ("owner_id") references "users" ("id") on update cascade on delete restrict
+);
+
+create table "events_acl" (
+    "id" integer not null default nextval('uid_seq'),
+    "event_id" integer not null,
+    "subject_class" varchar(8) not null,
+    "subject" text not null,
+    "role" text,
+    primary key("id"),
+    unique("event_id", "subject_class", "subject"),
+    foreign key ("event_id") references "events" ("id") on update cascade on delete cascade
+);
+
+alter table "program" add column "event_id" integer;
-- 
GitLab