From bb5f2bc2fe6a4b3e435f783661e2214e872c04d4 Mon Sep 17 00:00:00 2001 From: John Costa Date: Mon, 31 Mar 2025 18:10:04 +0000 Subject: [PATCH] feat(schema): basic contact tables --- .../.gen/haystack/haystack/model/contacts.go | 20 +++++ .../haystack/haystack/model/user_contacts.go | 18 ++++ .../.gen/haystack/haystack/table/contacts.go | 87 +++++++++++++++++++ .../haystack/table/table_use_schema.go | 2 + .../haystack/haystack/table/user_contacts.go | 81 +++++++++++++++++ backend/schema.sql | 17 ++++ 6 files changed, 225 insertions(+) create mode 100644 backend/.gen/haystack/haystack/model/contacts.go create mode 100644 backend/.gen/haystack/haystack/model/user_contacts.go create mode 100644 backend/.gen/haystack/haystack/table/contacts.go create mode 100644 backend/.gen/haystack/haystack/table/user_contacts.go diff --git a/backend/.gen/haystack/haystack/model/contacts.go b/backend/.gen/haystack/haystack/model/contacts.go new file mode 100644 index 0000000..da61883 --- /dev/null +++ b/backend/.gen/haystack/haystack/model/contacts.go @@ -0,0 +1,20 @@ +// +// Code generated by go-jet DO NOT EDIT. +// +// WARNING: Changes to this file may cause incorrect behavior +// and will be lost if the code is regenerated +// + +package model + +import ( + "github.com/google/uuid" +) + +type Contacts struct { + ID uuid.UUID `sql:"primary_key"` + Name string + Description *string + PhoneNumber *string + Email *string +} diff --git a/backend/.gen/haystack/haystack/model/user_contacts.go b/backend/.gen/haystack/haystack/model/user_contacts.go new file mode 100644 index 0000000..c48c9a6 --- /dev/null +++ b/backend/.gen/haystack/haystack/model/user_contacts.go @@ -0,0 +1,18 @@ +// +// Code generated by go-jet DO NOT EDIT. +// +// WARNING: Changes to this file may cause incorrect behavior +// and will be lost if the code is regenerated +// + +package model + +import ( + "github.com/google/uuid" +) + +type UserContacts struct { + ID uuid.UUID `sql:"primary_key"` + UserID uuid.UUID + ContactID uuid.UUID +} diff --git a/backend/.gen/haystack/haystack/table/contacts.go b/backend/.gen/haystack/haystack/table/contacts.go new file mode 100644 index 0000000..e849d5d --- /dev/null +++ b/backend/.gen/haystack/haystack/table/contacts.go @@ -0,0 +1,87 @@ +// +// Code generated by go-jet DO NOT EDIT. +// +// WARNING: Changes to this file may cause incorrect behavior +// and will be lost if the code is regenerated +// + +package table + +import ( + "github.com/go-jet/jet/v2/postgres" +) + +var Contacts = newContactsTable("haystack", "contacts", "") + +type contactsTable struct { + postgres.Table + + // Columns + ID postgres.ColumnString + Name postgres.ColumnString + Description postgres.ColumnString + PhoneNumber postgres.ColumnString + Email postgres.ColumnString + + AllColumns postgres.ColumnList + MutableColumns postgres.ColumnList +} + +type ContactsTable struct { + contactsTable + + EXCLUDED contactsTable +} + +// AS creates new ContactsTable with assigned alias +func (a ContactsTable) AS(alias string) *ContactsTable { + return newContactsTable(a.SchemaName(), a.TableName(), alias) +} + +// Schema creates new ContactsTable with assigned schema name +func (a ContactsTable) FromSchema(schemaName string) *ContactsTable { + return newContactsTable(schemaName, a.TableName(), a.Alias()) +} + +// WithPrefix creates new ContactsTable with assigned table prefix +func (a ContactsTable) WithPrefix(prefix string) *ContactsTable { + return newContactsTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new ContactsTable with assigned table suffix +func (a ContactsTable) WithSuffix(suffix string) *ContactsTable { + return newContactsTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + +func newContactsTable(schemaName, tableName, alias string) *ContactsTable { + return &ContactsTable{ + contactsTable: newContactsTableImpl(schemaName, tableName, alias), + EXCLUDED: newContactsTableImpl("", "excluded", ""), + } +} + +func newContactsTableImpl(schemaName, tableName, alias string) contactsTable { + var ( + IDColumn = postgres.StringColumn("id") + NameColumn = postgres.StringColumn("name") + DescriptionColumn = postgres.StringColumn("description") + PhoneNumberColumn = postgres.StringColumn("phone_number") + EmailColumn = postgres.StringColumn("email") + allColumns = postgres.ColumnList{IDColumn, NameColumn, DescriptionColumn, PhoneNumberColumn, EmailColumn} + mutableColumns = postgres.ColumnList{NameColumn, DescriptionColumn, PhoneNumberColumn, EmailColumn} + ) + + return contactsTable{ + Table: postgres.NewTable(schemaName, tableName, alias, allColumns...), + + //Columns + ID: IDColumn, + Name: NameColumn, + Description: DescriptionColumn, + PhoneNumber: PhoneNumberColumn, + Email: EmailColumn, + + AllColumns: allColumns, + MutableColumns: mutableColumns, + } +} diff --git a/backend/.gen/haystack/haystack/table/table_use_schema.go b/backend/.gen/haystack/haystack/table/table_use_schema.go index 1acb87d..aa53643 100644 --- a/backend/.gen/haystack/haystack/table/table_use_schema.go +++ b/backend/.gen/haystack/haystack/table/table_use_schema.go @@ -10,6 +10,7 @@ package table // UseSchema sets a new schema name for all generated table SQL builder types. It is recommended to invoke // this method only once at the beginning of the program. func UseSchema(schema string) { + Contacts = Contacts.FromSchema(schema) Events = Events.FromSchema(schema) Image = Image.FromSchema(schema) ImageEvents = ImageEvents.FromSchema(schema) @@ -18,6 +19,7 @@ func UseSchema(schema string) { ImageTags = ImageTags.FromSchema(schema) ImageText = ImageText.FromSchema(schema) Locations = Locations.FromSchema(schema) + UserContacts = UserContacts.FromSchema(schema) UserEvents = UserEvents.FromSchema(schema) UserImages = UserImages.FromSchema(schema) UserImagesToProcess = UserImagesToProcess.FromSchema(schema) diff --git a/backend/.gen/haystack/haystack/table/user_contacts.go b/backend/.gen/haystack/haystack/table/user_contacts.go new file mode 100644 index 0000000..954f9a2 --- /dev/null +++ b/backend/.gen/haystack/haystack/table/user_contacts.go @@ -0,0 +1,81 @@ +// +// Code generated by go-jet DO NOT EDIT. +// +// WARNING: Changes to this file may cause incorrect behavior +// and will be lost if the code is regenerated +// + +package table + +import ( + "github.com/go-jet/jet/v2/postgres" +) + +var UserContacts = newUserContactsTable("haystack", "user_contacts", "") + +type userContactsTable struct { + postgres.Table + + // Columns + ID postgres.ColumnString + UserID postgres.ColumnString + ContactID postgres.ColumnString + + AllColumns postgres.ColumnList + MutableColumns postgres.ColumnList +} + +type UserContactsTable struct { + userContactsTable + + EXCLUDED userContactsTable +} + +// AS creates new UserContactsTable with assigned alias +func (a UserContactsTable) AS(alias string) *UserContactsTable { + return newUserContactsTable(a.SchemaName(), a.TableName(), alias) +} + +// Schema creates new UserContactsTable with assigned schema name +func (a UserContactsTable) FromSchema(schemaName string) *UserContactsTable { + return newUserContactsTable(schemaName, a.TableName(), a.Alias()) +} + +// WithPrefix creates new UserContactsTable with assigned table prefix +func (a UserContactsTable) WithPrefix(prefix string) *UserContactsTable { + return newUserContactsTable(a.SchemaName(), prefix+a.TableName(), a.TableName()) +} + +// WithSuffix creates new UserContactsTable with assigned table suffix +func (a UserContactsTable) WithSuffix(suffix string) *UserContactsTable { + return newUserContactsTable(a.SchemaName(), a.TableName()+suffix, a.TableName()) +} + +func newUserContactsTable(schemaName, tableName, alias string) *UserContactsTable { + return &UserContactsTable{ + userContactsTable: newUserContactsTableImpl(schemaName, tableName, alias), + EXCLUDED: newUserContactsTableImpl("", "excluded", ""), + } +} + +func newUserContactsTableImpl(schemaName, tableName, alias string) userContactsTable { + var ( + IDColumn = postgres.StringColumn("id") + UserIDColumn = postgres.StringColumn("user_id") + ContactIDColumn = postgres.StringColumn("contact_id") + allColumns = postgres.ColumnList{IDColumn, UserIDColumn, ContactIDColumn} + mutableColumns = postgres.ColumnList{UserIDColumn, ContactIDColumn} + ) + + return userContactsTable{ + Table: postgres.NewTable(schemaName, tableName, alias, allColumns...), + + //Columns + ID: IDColumn, + UserID: UserIDColumn, + ContactID: ContactIDColumn, + + AllColumns: allColumns, + MutableColumns: mutableColumns, + } +} diff --git a/backend/schema.sql b/backend/schema.sql index 1a6bcde..8dd4637 100644 --- a/backend/schema.sql +++ b/backend/schema.sql @@ -94,6 +94,23 @@ CREATE TABLE haystack.user_events ( user_id UUID NOT NULL REFERENCES haystack.users (id) ); +CREATE TABLE haystack.contacts ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + + -- It seems name and description are frequent. We could use table inheritance. + name TEXT NOT NULL, + description TEXT, + + phone_number TEXT, + email TEXT +); + +CREATE TABLE haystack.user_contacts ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + user_id UUID NOT NULL REFERENCES haystack.users (id), + contact_id UUID NOT NULL REFERENCES haystack.contacts (id) +); + /* -----| Indexes |----- */ CREATE INDEX user_tags_index ON haystack.user_tags(tag);