From 3b6d0f81d269500627b9c71c07ac9854d70f50b5 Mon Sep 17 00:00:00 2001 From: Hein Date: Fri, 20 Feb 2026 16:19:49 +0200 Subject: [PATCH] feat(models): add new models for public API, event log, hook, session, user, and whatsapp account * Introduced ModelPublicAPIKey, ModelPublicEventLog, ModelPublicHook, ModelPublicSession, ModelPublicUser, and ModelPublicWhatsappAccount * Removed deprecated ModelPublicUsers * Updated database schema definitions to reflect new model structure * Adjusted seed data to use correct types for timestamps --- ...blic_api_keys.go => sql_public_api_key.go} | 33 +++++---- ..._event_logs.go => sql_public_event_log.go} | 35 +++++---- ...sql_public_hooks.go => sql_public_hook.go} | 33 +++++---- ...blic_sessions.go => sql_public_session.go} | 33 +++++---- pkg/models/sql_public_user.go | 67 +++++++++++++++++ pkg/models/sql_public_users.go | 72 ------------------- ...unts.go => sql_public_whatsapp_account.go} | 33 +++++---- pkg/storage/seed.go | 4 +- pkg/whatshooked/whatshooked.go | 2 +- sql/schema.dbml | 12 ++-- 10 files changed, 157 insertions(+), 167 deletions(-) rename pkg/models/{sql_public_api_keys.go => sql_public_api_key.go} (71%) rename pkg/models/{sql_public_event_logs.go => sql_public_event_log.go} (67%) rename pkg/models/{sql_public_hooks.go => sql_public_hook.go} (76%) rename pkg/models/{sql_public_sessions.go => sql_public_session.go} (64%) create mode 100644 pkg/models/sql_public_user.go delete mode 100644 pkg/models/sql_public_users.go rename pkg/models/{sql_public_whatsapp_accounts.go => sql_public_whatsapp_account.go} (73%) diff --git a/pkg/models/sql_public_api_keys.go b/pkg/models/sql_public_api_key.go similarity index 71% rename from pkg/models/sql_public_api_keys.go rename to pkg/models/sql_public_api_key.go index 5e30910..9e2ce4a 100644 --- a/pkg/models/sql_public_api_keys.go +++ b/pkg/models/sql_public_api_key.go @@ -7,8 +7,8 @@ import ( "github.com/uptrace/bun" ) -type ModelPublicAPIKeys struct { - bun.BaseModel `bun:"table:public.api_keys,alias:api_keys"` +type ModelPublicAPIKey struct { + bun.BaseModel `bun:"table:public.api_key,alias:api_key"` ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"` CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"` @@ -21,50 +21,49 @@ type ModelPublicAPIKeys struct { Permissions resolvespec_common.SqlString `bun:"permissions,type:text,nullzero," json:"permissions"` // JSON array of permissions UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"` UserID resolvespec_common.SqlString `bun:"user_id,type:varchar(36),notnull," json:"user_id"` - RelUserID *ModelPublicUsers `bun:"rel:has-one,join:user_id=id" json:"reluserid,omitempty"` // Has one ModelPublicUsers } -// TableName returns the table name for ModelPublicAPIKeys -func (m ModelPublicAPIKeys) TableName() string { - return "public.api_keys" +// TableName returns the table name for ModelPublicAPIKey +func (m ModelPublicAPIKey) TableName() string { + return "public.api_key" } -// TableNameOnly returns the table name without schema for ModelPublicAPIKeys -func (m ModelPublicAPIKeys) TableNameOnly() string { - return "api_keys" +// TableNameOnly returns the table name without schema for ModelPublicAPIKey +func (m ModelPublicAPIKey) TableNameOnly() string { + return "api_key" } -// SchemaName returns the schema name for ModelPublicAPIKeys -func (m ModelPublicAPIKeys) SchemaName() string { +// SchemaName returns the schema name for ModelPublicAPIKey +func (m ModelPublicAPIKey) SchemaName() string { return "public" } // GetID returns the primary key value -func (m ModelPublicAPIKeys) GetID() int64 { +func (m ModelPublicAPIKey) GetID() int64 { return m.ID.Int64() } // GetIDStr returns the primary key as a string -func (m ModelPublicAPIKeys) GetIDStr() string { +func (m ModelPublicAPIKey) GetIDStr() string { return fmt.Sprintf("%d", m.ID) } // SetID sets the primary key value -func (m ModelPublicAPIKeys) SetID(newid int64) { +func (m ModelPublicAPIKey) SetID(newid int64) { m.UpdateID(newid) } // UpdateID updates the primary key value -func (m *ModelPublicAPIKeys) UpdateID(newid int64) { +func (m *ModelPublicAPIKey) UpdateID(newid int64) { m.ID.FromString(fmt.Sprintf("%d", newid)) } // GetIDName returns the name of the primary key column -func (m ModelPublicAPIKeys) GetIDName() string { +func (m ModelPublicAPIKey) GetIDName() string { return "id" } // GetPrefix returns the table prefix -func (m ModelPublicAPIKeys) GetPrefix() string { +func (m ModelPublicAPIKey) GetPrefix() string { return "AKP" } diff --git a/pkg/models/sql_public_event_logs.go b/pkg/models/sql_public_event_log.go similarity index 67% rename from pkg/models/sql_public_event_logs.go rename to pkg/models/sql_public_event_log.go index b37c206..035079f 100644 --- a/pkg/models/sql_public_event_logs.go +++ b/pkg/models/sql_public_event_log.go @@ -7,8 +7,8 @@ import ( "github.com/uptrace/bun" ) -type ModelPublicEventLogs struct { - bun.BaseModel `bun:"table:public.event_logs,alias:event_logs"` +type ModelPublicEventLog struct { + bun.BaseModel `bun:"table:public.event_log,alias:event_log"` ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID Action resolvespec_common.SqlString `bun:"action,type:varchar(50),nullzero," json:"action"` // create CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"` @@ -20,51 +20,50 @@ type ModelPublicEventLogs struct { IpAddress resolvespec_common.SqlString `bun:"ip_address,type:varchar(50),nullzero," json:"ip_address"` Success bool `bun:"success,type:boolean,default:true,notnull," json:"success"` UserAgent resolvespec_common.SqlString `bun:"user_agent,type:text,nullzero," json:"user_agent"` - UserID resolvespec_common.SqlString `bun:"user_id,type:varchar(36),nullzero," json:"user_id"` // Optional user reference - RelUserID *ModelPublicUsers `bun:"rel:has-one,join:user_id=id" json:"reluserid,omitempty"` // Has one ModelPublicUsers + UserID resolvespec_common.SqlString `bun:"user_id,type:varchar(36),nullzero," json:"user_id"` // Optional user reference } -// TableName returns the table name for ModelPublicEventLogs -func (m ModelPublicEventLogs) TableName() string { - return "public.event_logs" +// TableName returns the table name for ModelPublicEventLog +func (m ModelPublicEventLog) TableName() string { + return "public.event_log" } -// TableNameOnly returns the table name without schema for ModelPublicEventLogs -func (m ModelPublicEventLogs) TableNameOnly() string { - return "event_logs" +// TableNameOnly returns the table name without schema for ModelPublicEventLog +func (m ModelPublicEventLog) TableNameOnly() string { + return "event_log" } -// SchemaName returns the schema name for ModelPublicEventLogs -func (m ModelPublicEventLogs) SchemaName() string { +// SchemaName returns the schema name for ModelPublicEventLog +func (m ModelPublicEventLog) SchemaName() string { return "public" } // GetID returns the primary key value -func (m ModelPublicEventLogs) GetID() int64 { +func (m ModelPublicEventLog) GetID() int64 { return m.ID.Int64() } // GetIDStr returns the primary key as a string -func (m ModelPublicEventLogs) GetIDStr() string { +func (m ModelPublicEventLog) GetIDStr() string { return fmt.Sprintf("%d", m.ID) } // SetID sets the primary key value -func (m ModelPublicEventLogs) SetID(newid int64) { +func (m ModelPublicEventLog) SetID(newid int64) { m.UpdateID(newid) } // UpdateID updates the primary key value -func (m *ModelPublicEventLogs) UpdateID(newid int64) { +func (m *ModelPublicEventLog) UpdateID(newid int64) { m.ID.FromString(fmt.Sprintf("%d", newid)) } // GetIDName returns the name of the primary key column -func (m ModelPublicEventLogs) GetIDName() string { +func (m ModelPublicEventLog) GetIDName() string { return "id" } // GetPrefix returns the table prefix -func (m ModelPublicEventLogs) GetPrefix() string { +func (m ModelPublicEventLog) GetPrefix() string { return "ELV" } diff --git a/pkg/models/sql_public_hooks.go b/pkg/models/sql_public_hook.go similarity index 76% rename from pkg/models/sql_public_hooks.go rename to pkg/models/sql_public_hook.go index 9c49b11..47f5b85 100644 --- a/pkg/models/sql_public_hooks.go +++ b/pkg/models/sql_public_hook.go @@ -7,8 +7,8 @@ import ( "github.com/uptrace/bun" ) -type ModelPublicHooks struct { - bun.BaseModel `bun:"table:public.hooks,alias:hooks"` +type ModelPublicHook struct { + bun.BaseModel `bun:"table:public.hook,alias:hook"` ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"` AllowInsecure bool `bun:"allow_insecure,type:boolean,default:false,notnull," json:"allow_insecure"` // Skip TLS certificate verification @@ -25,50 +25,49 @@ type ModelPublicHooks struct { UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"` URL resolvespec_common.SqlString `bun:"url,type:text,notnull," json:"url"` UserID resolvespec_common.SqlString `bun:"user_id,type:varchar(36),notnull," json:"user_id"` - RelUserID *ModelPublicUsers `bun:"rel:has-one,join:user_id=id" json:"reluserid,omitempty"` // Has one ModelPublicUsers } -// TableName returns the table name for ModelPublicHooks -func (m ModelPublicHooks) TableName() string { - return "public.hooks" +// TableName returns the table name for ModelPublicHook +func (m ModelPublicHook) TableName() string { + return "public.hook" } -// TableNameOnly returns the table name without schema for ModelPublicHooks -func (m ModelPublicHooks) TableNameOnly() string { - return "hooks" +// TableNameOnly returns the table name without schema for ModelPublicHook +func (m ModelPublicHook) TableNameOnly() string { + return "hook" } -// SchemaName returns the schema name for ModelPublicHooks -func (m ModelPublicHooks) SchemaName() string { +// SchemaName returns the schema name for ModelPublicHook +func (m ModelPublicHook) SchemaName() string { return "public" } // GetID returns the primary key value -func (m ModelPublicHooks) GetID() int64 { +func (m ModelPublicHook) GetID() int64 { return m.ID.Int64() } // GetIDStr returns the primary key as a string -func (m ModelPublicHooks) GetIDStr() string { +func (m ModelPublicHook) GetIDStr() string { return fmt.Sprintf("%d", m.ID) } // SetID sets the primary key value -func (m ModelPublicHooks) SetID(newid int64) { +func (m ModelPublicHook) SetID(newid int64) { m.UpdateID(newid) } // UpdateID updates the primary key value -func (m *ModelPublicHooks) UpdateID(newid int64) { +func (m *ModelPublicHook) UpdateID(newid int64) { m.ID.FromString(fmt.Sprintf("%d", newid)) } // GetIDName returns the name of the primary key column -func (m ModelPublicHooks) GetIDName() string { +func (m ModelPublicHook) GetIDName() string { return "id" } // GetPrefix returns the table prefix -func (m ModelPublicHooks) GetPrefix() string { +func (m ModelPublicHook) GetPrefix() string { return "HOO" } diff --git a/pkg/models/sql_public_sessions.go b/pkg/models/sql_public_session.go similarity index 64% rename from pkg/models/sql_public_sessions.go rename to pkg/models/sql_public_session.go index e85777b..5e24a91 100644 --- a/pkg/models/sql_public_sessions.go +++ b/pkg/models/sql_public_session.go @@ -7,8 +7,8 @@ import ( "github.com/uptrace/bun" ) -type ModelPublicSessions struct { - bun.BaseModel `bun:"table:public.sessions,alias:sessions"` +type ModelPublicSession struct { + bun.BaseModel `bun:"table:public.session,alias:session"` ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"` ExpiresAt resolvespec_common.SqlTimeStamp `bun:"expires_at,type:timestamp,notnull," json:"expires_at"` @@ -17,50 +17,49 @@ type ModelPublicSessions struct { UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"` UserAgent resolvespec_common.SqlString `bun:"user_agent,type:text,nullzero," json:"user_agent"` UserID resolvespec_common.SqlString `bun:"user_id,type:varchar(36),notnull," json:"user_id"` - RelUserID *ModelPublicUsers `bun:"rel:has-one,join:user_id=id" json:"reluserid,omitempty"` // Has one ModelPublicUsers } -// TableName returns the table name for ModelPublicSessions -func (m ModelPublicSessions) TableName() string { - return "public.sessions" +// TableName returns the table name for ModelPublicSession +func (m ModelPublicSession) TableName() string { + return "public.session" } -// TableNameOnly returns the table name without schema for ModelPublicSessions -func (m ModelPublicSessions) TableNameOnly() string { - return "sessions" +// TableNameOnly returns the table name without schema for ModelPublicSession +func (m ModelPublicSession) TableNameOnly() string { + return "session" } -// SchemaName returns the schema name for ModelPublicSessions -func (m ModelPublicSessions) SchemaName() string { +// SchemaName returns the schema name for ModelPublicSession +func (m ModelPublicSession) SchemaName() string { return "public" } // GetID returns the primary key value -func (m ModelPublicSessions) GetID() int64 { +func (m ModelPublicSession) GetID() int64 { return m.ID.Int64() } // GetIDStr returns the primary key as a string -func (m ModelPublicSessions) GetIDStr() string { +func (m ModelPublicSession) GetIDStr() string { return fmt.Sprintf("%d", m.ID) } // SetID sets the primary key value -func (m ModelPublicSessions) SetID(newid int64) { +func (m ModelPublicSession) SetID(newid int64) { m.UpdateID(newid) } // UpdateID updates the primary key value -func (m *ModelPublicSessions) UpdateID(newid int64) { +func (m *ModelPublicSession) UpdateID(newid int64) { m.ID.FromString(fmt.Sprintf("%d", newid)) } // GetIDName returns the name of the primary key column -func (m ModelPublicSessions) GetIDName() string { +func (m ModelPublicSession) GetIDName() string { return "id" } // GetPrefix returns the table prefix -func (m ModelPublicSessions) GetPrefix() string { +func (m ModelPublicSession) GetPrefix() string { return "SES" } diff --git a/pkg/models/sql_public_user.go b/pkg/models/sql_public_user.go new file mode 100644 index 0000000..14c144e --- /dev/null +++ b/pkg/models/sql_public_user.go @@ -0,0 +1,67 @@ +// Code generated by relspecgo. DO NOT EDIT. +package models + +import ( + "fmt" + resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" + "github.com/uptrace/bun" +) + +type ModelPublicUser struct { + bun.BaseModel `bun:"table:public.user,alias:user"` + ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID + Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"` + CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"` + DeletedAt resolvespec_common.SqlTimeStamp `bun:"deleted_at,type:timestamp,nullzero," json:"deleted_at"` // Soft delete + Email resolvespec_common.SqlString `bun:"email,type:varchar(255),notnull," json:"email"` + FullName resolvespec_common.SqlString `bun:"full_name,type:varchar(255),nullzero," json:"full_name"` + Password resolvespec_common.SqlString `bun:"password,type:varchar(255),notnull," json:"password"` // Bcrypt hashed password + Role resolvespec_common.SqlString `bun:"role,type:varchar(50),default:'user',notnull," json:"role"` // admin + UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"` + Username resolvespec_common.SqlString `bun:"username,type:varchar(255),notnull," json:"username"` +} + +// TableName returns the table name for ModelPublicUser +func (m ModelPublicUser) TableName() string { + return "public.user" +} + +// TableNameOnly returns the table name without schema for ModelPublicUser +func (m ModelPublicUser) TableNameOnly() string { + return "user" +} + +// SchemaName returns the schema name for ModelPublicUser +func (m ModelPublicUser) SchemaName() string { + return "public" +} + +// GetID returns the primary key value +func (m ModelPublicUser) GetID() int64 { + return m.ID.Int64() +} + +// GetIDStr returns the primary key as a string +func (m ModelPublicUser) GetIDStr() string { + return fmt.Sprintf("%d", m.ID) +} + +// SetID sets the primary key value +func (m ModelPublicUser) SetID(newid int64) { + m.UpdateID(newid) +} + +// UpdateID updates the primary key value +func (m *ModelPublicUser) UpdateID(newid int64) { + m.ID.FromString(fmt.Sprintf("%d", newid)) +} + +// GetIDName returns the name of the primary key column +func (m ModelPublicUser) GetIDName() string { + return "id" +} + +// GetPrefix returns the table prefix +func (m ModelPublicUser) GetPrefix() string { + return "USE" +} diff --git a/pkg/models/sql_public_users.go b/pkg/models/sql_public_users.go deleted file mode 100644 index 89cece6..0000000 --- a/pkg/models/sql_public_users.go +++ /dev/null @@ -1,72 +0,0 @@ -// Code generated by relspecgo. DO NOT EDIT. -package models - -import ( - "fmt" - resolvespec_common "github.com/bitechdev/ResolveSpec/pkg/spectypes" - "github.com/uptrace/bun" -) - -type ModelPublicUsers struct { - bun.BaseModel `bun:"table:public.users,alias:users"` - ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID - Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"` - CreatedAt resolvespec_common.SqlTimeStamp `bun:"created_at,type:timestamp,default:now(),notnull," json:"created_at"` - DeletedAt resolvespec_common.SqlTimeStamp `bun:"deleted_at,type:timestamp,nullzero," json:"deleted_at"` // Soft delete - Email resolvespec_common.SqlString `bun:"email,type:varchar(255),notnull," json:"email"` - FullName resolvespec_common.SqlString `bun:"full_name,type:varchar(255),nullzero," json:"full_name"` - Password resolvespec_common.SqlString `bun:"password,type:varchar(255),notnull," json:"password"` // Bcrypt hashed password - Role resolvespec_common.SqlString `bun:"role,type:varchar(50),default:'user',notnull," json:"role"` // admin - UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"` - Username resolvespec_common.SqlString `bun:"username,type:varchar(255),notnull," json:"username"` - RelUserIDPublicAPIKeys []*ModelPublicAPIKeys `bun:"rel:has-many,join:id=user_id" json:"reluseridpublicapikeys,omitempty"` // Has many ModelPublicAPIKeys - RelUserIDPublicHooks []*ModelPublicHooks `bun:"rel:has-many,join:id=user_id" json:"reluseridpublichooks,omitempty"` // Has many ModelPublicHooks - RelUserIDPublicWhatsappAccounts []*ModelPublicWhatsappAccounts `bun:"rel:has-many,join:id=user_id" json:"reluseridpublicwhatsappaccounts,omitempty"` // Has many ModelPublicWhatsappAccounts - RelUserIDPublicEventLogs []*ModelPublicEventLogs `bun:"rel:has-many,join:id=user_id" json:"reluseridpubliceventlogs,omitempty"` // Has many ModelPublicEventLogs - RelUserIDPublicSessions []*ModelPublicSessions `bun:"rel:has-many,join:id=user_id" json:"reluseridpublicsessions,omitempty"` // Has many ModelPublicSessions -} - -// TableName returns the table name for ModelPublicUsers -func (m ModelPublicUsers) TableName() string { - return "public.users" -} - -// TableNameOnly returns the table name without schema for ModelPublicUsers -func (m ModelPublicUsers) TableNameOnly() string { - return "users" -} - -// SchemaName returns the schema name for ModelPublicUsers -func (m ModelPublicUsers) SchemaName() string { - return "public" -} - -// GetID returns the primary key value -func (m ModelPublicUsers) GetID() int64 { - return m.ID.Int64() -} - -// GetIDStr returns the primary key as a string -func (m ModelPublicUsers) GetIDStr() string { - return fmt.Sprintf("%d", m.ID) -} - -// SetID sets the primary key value -func (m ModelPublicUsers) SetID(newid int64) { - m.UpdateID(newid) -} - -// UpdateID updates the primary key value -func (m *ModelPublicUsers) UpdateID(newid int64) { - m.ID.FromString(fmt.Sprintf("%d", newid)) -} - -// GetIDName returns the name of the primary key column -func (m ModelPublicUsers) GetIDName() string { - return "id" -} - -// GetPrefix returns the table prefix -func (m ModelPublicUsers) GetPrefix() string { - return "USE" -} diff --git a/pkg/models/sql_public_whatsapp_accounts.go b/pkg/models/sql_public_whatsapp_account.go similarity index 73% rename from pkg/models/sql_public_whatsapp_accounts.go rename to pkg/models/sql_public_whatsapp_account.go index 0bb715c..163b0d9 100644 --- a/pkg/models/sql_public_whatsapp_accounts.go +++ b/pkg/models/sql_public_whatsapp_account.go @@ -7,8 +7,8 @@ import ( "github.com/uptrace/bun" ) -type ModelPublicWhatsappAccounts struct { - bun.BaseModel `bun:"table:public.whatsapp_accounts,alias:whatsapp_accounts"` +type ModelPublicWhatsappAccount struct { + bun.BaseModel `bun:"table:public.whatsapp_account,alias:whatsapp_account"` ID resolvespec_common.SqlString `bun:"id,type:varchar(36),pk," json:"id"` // UUID AccountType resolvespec_common.SqlString `bun:"account_type,type:varchar(50),notnull," json:"account_type"` // whatsmeow or business-api Active bool `bun:"active,type:boolean,default:true,notnull," json:"active"` @@ -22,50 +22,49 @@ type ModelPublicWhatsappAccounts struct { Status resolvespec_common.SqlString `bun:"status,type:varchar(50),default:'disconnected',notnull," json:"status"` // connected UpdatedAt resolvespec_common.SqlTimeStamp `bun:"updated_at,type:timestamp,default:now(),notnull," json:"updated_at"` UserID resolvespec_common.SqlString `bun:"user_id,type:varchar(36),notnull," json:"user_id"` - RelUserID *ModelPublicUsers `bun:"rel:has-one,join:user_id=id" json:"reluserid,omitempty"` // Has one ModelPublicUsers } -// TableName returns the table name for ModelPublicWhatsappAccounts -func (m ModelPublicWhatsappAccounts) TableName() string { - return "public.whatsapp_accounts" +// TableName returns the table name for ModelPublicWhatsappAccount +func (m ModelPublicWhatsappAccount) TableName() string { + return "public.whatsapp_account" } -// TableNameOnly returns the table name without schema for ModelPublicWhatsappAccounts -func (m ModelPublicWhatsappAccounts) TableNameOnly() string { - return "whatsapp_accounts" +// TableNameOnly returns the table name without schema for ModelPublicWhatsappAccount +func (m ModelPublicWhatsappAccount) TableNameOnly() string { + return "whatsapp_account" } -// SchemaName returns the schema name for ModelPublicWhatsappAccounts -func (m ModelPublicWhatsappAccounts) SchemaName() string { +// SchemaName returns the schema name for ModelPublicWhatsappAccount +func (m ModelPublicWhatsappAccount) SchemaName() string { return "public" } // GetID returns the primary key value -func (m ModelPublicWhatsappAccounts) GetID() int64 { +func (m ModelPublicWhatsappAccount) GetID() int64 { return m.ID.Int64() } // GetIDStr returns the primary key as a string -func (m ModelPublicWhatsappAccounts) GetIDStr() string { +func (m ModelPublicWhatsappAccount) GetIDStr() string { return fmt.Sprintf("%d", m.ID) } // SetID sets the primary key value -func (m ModelPublicWhatsappAccounts) SetID(newid int64) { +func (m ModelPublicWhatsappAccount) SetID(newid int64) { m.UpdateID(newid) } // UpdateID updates the primary key value -func (m *ModelPublicWhatsappAccounts) UpdateID(newid int64) { +func (m *ModelPublicWhatsappAccount) UpdateID(newid int64) { m.ID.FromString(fmt.Sprintf("%d", newid)) } // GetIDName returns the name of the primary key column -func (m ModelPublicWhatsappAccounts) GetIDName() string { +func (m ModelPublicWhatsappAccount) GetIDName() string { return "id" } // GetPrefix returns the table prefix -func (m ModelPublicWhatsappAccounts) GetPrefix() string { +func (m ModelPublicWhatsappAccount) GetPrefix() string { return "WAH" } diff --git a/pkg/storage/seed.go b/pkg/storage/seed.go index 60e512f..a53e30b 100644 --- a/pkg/storage/seed.go +++ b/pkg/storage/seed.go @@ -40,8 +40,8 @@ func SeedData(ctx context.Context) error { FullName: resolvespec_common.NewSqlString("System Administrator"), Role: resolvespec_common.NewSqlString("admin"), Active: true, - CreatedAt: resolvespec_common.NewSqlTime(now), - UpdatedAt: resolvespec_common.NewSqlTime(now), + CreatedAt: resolvespec_common.NewSqlTimeStamp(now), + UpdatedAt: resolvespec_common.NewSqlTimeStamp(now), } if err := userRepo.Create(ctx, adminUser); err != nil { diff --git a/pkg/whatshooked/whatshooked.go b/pkg/whatshooked/whatshooked.go index eba7ba7..e3a61bb 100644 --- a/pkg/whatshooked/whatshooked.go +++ b/pkg/whatshooked/whatshooked.go @@ -165,7 +165,7 @@ func (wh *WhatsHooked) connectFromDatabase(ctx context.Context) error { for _, account := range accounts { // Skip if account_id is not set - accountID := account.AccountID.String() + accountID := account.ID.String() if accountID == "" { accountID = account.ID.String() // Fall back to UUID if account_id not set } diff --git a/sql/schema.dbml b/sql/schema.dbml index ef1c233..aaa911a 100644 --- a/sql/schema.dbml +++ b/sql/schema.dbml @@ -1,7 +1,7 @@ // WhatsHooked Database Schema // This file defines the database schema for WhatsHooked Phase 2 -Table users { +Table user { id varchar(36) [primary key, note: 'UUID'] username varchar(255) [unique, not null] email varchar(255) [unique, not null] @@ -18,7 +18,7 @@ Table users { } } -Table api_keys { +Table api_key { id varchar(36) [primary key, note: 'UUID'] user_id varchar(36) [not null, ref: > users.id] name varchar(255) [not null, note: 'Friendly name for the API key'] @@ -38,7 +38,7 @@ Table api_keys { } } -Table hooks { +Table hook { id varchar(36) [primary key, note: 'UUID'] user_id varchar(36) [not null, ref: > users.id] name varchar(255) [not null] @@ -62,7 +62,7 @@ Table hooks { } } -Table whatsapp_accounts { +Table whatsapp_account { id varchar(36) [primary key, note: 'UUID'] user_id varchar(36) [not null, ref: > users.id] account_type varchar(50) [not null, note: 'whatsmeow or business-api'] @@ -83,7 +83,7 @@ Table whatsapp_accounts { } } -Table event_logs { +Table event_log { id varchar(36) [primary key, note: 'UUID'] user_id varchar(36) [ref: > users.id, note: 'Optional user reference'] event_type varchar(100) [not null] @@ -106,7 +106,7 @@ Table event_logs { } } -Table sessions { +Table session { id varchar(36) [primary key, note: 'UUID'] user_id varchar(36) [not null, ref: > users.id] token varchar(255) [unique, not null, note: 'Session token hash']