feat(schema): basic contact tables
This commit is contained in:
20
backend/.gen/haystack/haystack/model/contacts.go
Normal file
20
backend/.gen/haystack/haystack/model/contacts.go
Normal file
@ -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
|
||||||
|
}
|
18
backend/.gen/haystack/haystack/model/user_contacts.go
Normal file
18
backend/.gen/haystack/haystack/model/user_contacts.go
Normal file
@ -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
|
||||||
|
}
|
87
backend/.gen/haystack/haystack/table/contacts.go
Normal file
87
backend/.gen/haystack/haystack/table/contacts.go
Normal file
@ -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,
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ package table
|
|||||||
// UseSchema sets a new schema name for all generated table SQL builder types. It is recommended to invoke
|
// 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.
|
// this method only once at the beginning of the program.
|
||||||
func UseSchema(schema string) {
|
func UseSchema(schema string) {
|
||||||
|
Contacts = Contacts.FromSchema(schema)
|
||||||
Events = Events.FromSchema(schema)
|
Events = Events.FromSchema(schema)
|
||||||
Image = Image.FromSchema(schema)
|
Image = Image.FromSchema(schema)
|
||||||
ImageEvents = ImageEvents.FromSchema(schema)
|
ImageEvents = ImageEvents.FromSchema(schema)
|
||||||
@ -18,6 +19,7 @@ func UseSchema(schema string) {
|
|||||||
ImageTags = ImageTags.FromSchema(schema)
|
ImageTags = ImageTags.FromSchema(schema)
|
||||||
ImageText = ImageText.FromSchema(schema)
|
ImageText = ImageText.FromSchema(schema)
|
||||||
Locations = Locations.FromSchema(schema)
|
Locations = Locations.FromSchema(schema)
|
||||||
|
UserContacts = UserContacts.FromSchema(schema)
|
||||||
UserEvents = UserEvents.FromSchema(schema)
|
UserEvents = UserEvents.FromSchema(schema)
|
||||||
UserImages = UserImages.FromSchema(schema)
|
UserImages = UserImages.FromSchema(schema)
|
||||||
UserImagesToProcess = UserImagesToProcess.FromSchema(schema)
|
UserImagesToProcess = UserImagesToProcess.FromSchema(schema)
|
||||||
|
81
backend/.gen/haystack/haystack/table/user_contacts.go
Normal file
81
backend/.gen/haystack/haystack/table/user_contacts.go
Normal file
@ -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,
|
||||||
|
}
|
||||||
|
}
|
@ -94,6 +94,23 @@ CREATE TABLE haystack.user_events (
|
|||||||
user_id UUID NOT NULL REFERENCES haystack.users (id)
|
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 |----- */
|
/* -----| Indexes |----- */
|
||||||
|
|
||||||
CREATE INDEX user_tags_index ON haystack.user_tags(tag);
|
CREATE INDEX user_tags_index ON haystack.user_tags(tag);
|
||||||
|
Reference in New Issue
Block a user