diff --git a/cmd/api/auth/handler.go b/cmd/api/auth/handler.go index a49f9e0..4114adb 100644 --- a/cmd/api/auth/handler.go +++ b/cmd/api/auth/handler.go @@ -5,7 +5,7 @@ import ( "encoding/json" "net/http" - "ahbcc/cmd/api/users" + "ahbcc/cmd/api/user" ) // SignUpHandlerV1 HTTP Handler of the endpoint /auth/signup @@ -13,7 +13,7 @@ func SignUpHandlerV1(signUp SignUp) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { ctx := r.Context() - var user users.UserDTO + var user user.DTO err := json.NewDecoder(r.Body).Decode(&user) if err != nil { log.Error(ctx, err.Error()) @@ -41,7 +41,7 @@ func SignUpHandlerV1(signUp SignUp) http.HandlerFunc { } // validateBody validates that mandatory fields are present -func validateBody(user users.UserDTO) error { +func validateBody(user user.DTO) error { if user.Username == "" { return MissingUsername } diff --git a/cmd/api/auth/handler_test.go b/cmd/api/auth/handler_test.go index aaf445b..f19fa8f 100644 --- a/cmd/api/auth/handler_test.go +++ b/cmd/api/auth/handler_test.go @@ -12,13 +12,13 @@ import ( "github.com/stretchr/testify/assert" "ahbcc/cmd/api/auth" - "ahbcc/cmd/api/users" + "ahbcc/cmd/api/user" ) func TestSignUpHandlerV1_success(t *testing.T) { mockSignUp := auth.MockSignUp(nil) mockResponseWriter := httptest.NewRecorder() - mockUser := users.MockUserDTO() + mockUser := user.MockDTO() mockBody, _ := json.Marshal(mockUser) mockRequest, _ := http.NewRequestWithContext(context.Background(), http.MethodPost, "/auth/signup/v1", bytes.NewReader(mockBody)) @@ -53,10 +53,10 @@ func TestSignUpHandlerV1_failsWhenValidateBodyThrowsError(t *testing.T) { mockResponseWriter := httptest.NewRecorder() for _, test := range []struct { - mockUser users.UserDTO + mockUser user.DTO }{ - {mockUser: users.UserDTO{Username: "username"}}, - {mockUser: users.UserDTO{Password: "password"}}, + {mockUser: user.DTO{Username: "username"}}, + {mockUser: user.DTO{Password: "password"}}, } { mockBody, _ := json.Marshal(test.mockUser) mockRequest, _ := http.NewRequestWithContext(context.Background(), http.MethodPost, "/auth/signup/v1", bytes.NewReader(mockBody)) @@ -75,7 +75,7 @@ func TestSignUpHandlerV1_failsWhenValidateBodyThrowsError(t *testing.T) { func TestSignUpHandlerV1_failsWhenSignUpThrowsError(t *testing.T) { mockSignUp := auth.MockSignUp(errors.New("failed to sign up")) mockResponseWriter := httptest.NewRecorder() - mockUser := users.MockUserDTO() + mockUser := user.MockDTO() mockBody, _ := json.Marshal(mockUser) mockRequest, _ := http.NewRequestWithContext(context.Background(), http.MethodPost, "/auth/signup/v1", bytes.NewReader(mockBody)) diff --git a/cmd/api/auth/mocks.go b/cmd/api/auth/mocks.go index 299bb10..c1a8f08 100644 --- a/cmd/api/auth/mocks.go +++ b/cmd/api/auth/mocks.go @@ -2,13 +2,13 @@ package auth import ( "context" - - "ahbcc/cmd/api/users" + + "ahbcc/cmd/api/user" ) // MockSignUp mocks SignUp function func MockSignUp(err error) SignUp { - return func(ctx context.Context, user users.UserDTO) error { + return func(ctx context.Context, user user.DTO) error { return err } } diff --git a/cmd/api/auth/signup_test.go b/cmd/api/auth/signup_test.go index f58371b..dadf4ab 100644 --- a/cmd/api/auth/signup_test.go +++ b/cmd/api/auth/signup_test.go @@ -8,13 +8,13 @@ import ( "github.com/stretchr/testify/assert" "ahbcc/cmd/api/auth" - "ahbcc/cmd/api/users" + "ahbcc/cmd/api/user" ) func TestSignUp_success(t *testing.T) { - mockUserExists := users.MockUserExists(false, nil) - mockInsertUser := users.MockInsert(nil) - mockUserDTO := users.MockUserDTO() + mockUserExists := user.MockExists(false, nil) + mockInsertUser := user.MockInsert(nil) + mockUserDTO := user.MockDTO() signUp := auth.MakeSignUp(mockUserExists, mockInsertUser) @@ -24,9 +24,9 @@ func TestSignUp_success(t *testing.T) { } func TestSignUp_failsWhenUserExistsThrowsError(t *testing.T) { - mockUserExists := users.MockUserExists(false, errors.New("failed to execute UserExists")) - mockInsertUser := users.MockInsert(nil) - mockUserDTO := users.MockUserDTO() + mockUserExists := user.MockExists(false, errors.New("failed to execute Exists")) + mockInsertUser := user.MockInsert(nil) + mockUserDTO := user.MockDTO() signUp := auth.MakeSignUp(mockUserExists, mockInsertUser) @@ -37,9 +37,9 @@ func TestSignUp_failsWhenUserExistsThrowsError(t *testing.T) { } func TestSignUp_failsWhenUserAlreadyExists(t *testing.T) { - mockUserExists := users.MockUserExists(true, nil) - mockInsertUser := users.MockInsert(nil) - mockUserDTO := users.MockUserDTO() + mockUserExists := user.MockExists(true, nil) + mockInsertUser := user.MockInsert(nil) + mockUserDTO := user.MockDTO() signUp := auth.MakeSignUp(mockUserExists, mockInsertUser) @@ -50,9 +50,9 @@ func TestSignUp_failsWhenUserAlreadyExists(t *testing.T) { } func TestSignUp_failsWhenGenerateFromPasswordThrowsError(t *testing.T) { - mockUserExists := users.MockUserExists(false, nil) - mockInsertUser := users.MockInsert(nil) - mockUserDTO := users.MockUserDTO() + mockUserExists := user.MockExists(false, nil) + mockInsertUser := user.MockInsert(nil) + mockUserDTO := user.MockDTO() mockUserDTO.Password = "verylongpassword1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" signUp := auth.MakeSignUp(mockUserExists, mockInsertUser) @@ -64,9 +64,9 @@ func TestSignUp_failsWhenGenerateFromPasswordThrowsError(t *testing.T) { } func TestSignUp_failsWhenInsertThrowsError(t *testing.T) { - mockUserExists := users.MockUserExists(false, nil) - mockInsertUser := users.MockInsert(errors.New("failed to insert user")) - mockUserDTO := users.MockUserDTO() + mockUserExists := user.MockExists(false, nil) + mockInsertUser := user.MockInsert(errors.New("failed to insert user")) + mockUserDTO := user.MockDTO() signUp := auth.MakeSignUp(mockUserExists, mockInsertUser) diff --git a/cmd/api/auth/singup.go b/cmd/api/auth/singup.go index 00664a1..7bbca9c 100644 --- a/cmd/api/auth/singup.go +++ b/cmd/api/auth/singup.go @@ -4,16 +4,16 @@ import ( "context" "golang.org/x/crypto/bcrypt" - "ahbcc/cmd/api/users" + "ahbcc/cmd/api/user" "ahbcc/internal/log" ) // SignUp registers a new user in the system -type SignUp func(ctx context.Context, user users.UserDTO) error +type SignUp func(ctx context.Context, user user.DTO) error // MakeSignUp creates a new SignUp -func MakeSignUp(userExists users.UserExists, insertUser users.Insert) SignUp { - return func(ctx context.Context, user users.UserDTO) error { +func MakeSignUp(userExists user.Exists, insertUser user.Insert) SignUp { + return func(ctx context.Context, user user.DTO) error { exists, err := userExists(ctx, user.Username) if err != nil { log.Error(ctx, err.Error()) diff --git a/cmd/api/main.go b/cmd/api/main.go index 2d69b92..df058e9 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -15,7 +15,7 @@ import ( "ahbcc/cmd/api/search/criteria" "ahbcc/cmd/api/tweets" "ahbcc/cmd/api/tweets/quotes" - "ahbcc/cmd/api/users" + "ahbcc/cmd/api/user" "ahbcc/internal/database" _http "ahbcc/internal/http" "ahbcc/internal/log" @@ -54,8 +54,8 @@ func main() { insertAppliedMigration := migrations.MakeInsertAppliedMigration(db) runMigrations := migrations.MakeRun(db, createMigrationsTable, isMigrationApplied, insertAppliedMigration) - userExists := users.MakeUserExists(db) - insertUser := users.MakeInsert(db) + userExists := user.MakeExists(db) + insertUser := user.MakeInsert(db) signUp := auth.MakeSignUp(userExists, insertUser) insertSingleQuote := quotes.MakeInsertSingle(db) diff --git a/cmd/api/user/dao.go b/cmd/api/user/dao.go new file mode 100644 index 0000000..49ea9b2 --- /dev/null +++ b/cmd/api/user/dao.go @@ -0,0 +1,11 @@ +package user + +import "time" + +// DAO represents a user +type DAO struct { + ID int `json:"id"` + Username string `json:"username"` + Password string `json:"password_hash"` + CreatedAt time.Time `json:"created_at"` +} diff --git a/cmd/api/user/dtos.go b/cmd/api/user/dtos.go new file mode 100644 index 0000000..e0b5a2a --- /dev/null +++ b/cmd/api/user/dtos.go @@ -0,0 +1,7 @@ +package user + +// DTO represents a user to be inserted into the 'user' table +type DTO struct { + Username string `json:"username"` + Password string `json:"password"` +} diff --git a/cmd/api/user/errors.go b/cmd/api/user/errors.go new file mode 100644 index 0000000..ff04edf --- /dev/null +++ b/cmd/api/user/errors.go @@ -0,0 +1,10 @@ +package user + +import "errors" + +var ( + FailedToInsertUser = errors.New("failed to insert user") + FailedToRetrieveIfUserAlreadyExists = errors.New("failed to retrieve if user already exists") + NoUserFoundForTheGivenUsername = errors.New("no user found for the given username") + FailedExecuteQueryToRetrieveUser = errors.New("failed to execute query to retrieve user") +) diff --git a/cmd/api/users/insert.go b/cmd/api/user/insert.go similarity index 65% rename from cmd/api/users/insert.go rename to cmd/api/user/insert.go index 8a62982..4c35f54 100644 --- a/cmd/api/users/insert.go +++ b/cmd/api/user/insert.go @@ -1,4 +1,4 @@ -package users +package user import ( "context" @@ -7,18 +7,18 @@ import ( "ahbcc/internal/log" ) -// Insert inserts a new UserDTO into 'users' table -type Insert func(ctx context.Context, user UserDTO) error +// Insert inserts a new DTO into 'user' table +type Insert func(ctx context.Context, user DTO) error // MakeInsert creates a new Insert func MakeInsert(db database.Connection) Insert { const query string = ` - INSERT INTO users(username, password_hash) + INSERT INTO user(username, password_hash) VALUES ($1, $2) ON CONFLICT (username, password_hash) DO NOTHING; ` - return func(ctx context.Context, user UserDTO) error { + return func(ctx context.Context, user DTO) error { _, err := db.Exec(ctx, query, user.Username, user.Password) if err != nil { log.Error(ctx, err.Error()) diff --git a/cmd/api/users/insert_test.go b/cmd/api/user/insert_test.go similarity index 78% rename from cmd/api/users/insert_test.go rename to cmd/api/user/insert_test.go index 70f9775..babce17 100644 --- a/cmd/api/users/insert_test.go +++ b/cmd/api/user/insert_test.go @@ -1,4 +1,4 @@ -package users_test +package user_test import ( "context" @@ -9,16 +9,16 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "ahbcc/cmd/api/users" + "ahbcc/cmd/api/user" "ahbcc/internal/database" ) func TestInsert_success(t *testing.T) { mockPostgresConnection := new(database.MockPostgresConnection) mockPostgresConnection.On("Exec", mock.Anything, mock.Anything, mock.Anything).Return(pgconn.CommandTag{}, nil) - mockUserDTO := users.MockUserDTO() + mockUserDTO := user.MockDTO() - insertUser := users.MakeInsert(mockPostgresConnection) + insertUser := user.MakeInsert(mockPostgresConnection) got := insertUser(context.Background(), mockUserDTO) @@ -29,11 +29,11 @@ func TestInsert_success(t *testing.T) { func TestInsert_failsWhenInsertOperationThrowsError(t *testing.T) { mockPostgresConnection := new(database.MockPostgresConnection) mockPostgresConnection.On("Exec", mock.Anything, mock.Anything, mock.Anything).Return(pgconn.CommandTag{}, errors.New("failed to insert user")) - mockUserDTO := users.MockUserDTO() + mockUserDTO := user.MockDTO() - insertUser := users.MakeInsert(mockPostgresConnection) + insertUser := user.MakeInsert(mockPostgresConnection) - want := users.FailedToInsertUser + want := user.FailedToInsertUser got := insertUser(context.Background(), mockUserDTO) assert.Equal(t, want, got) diff --git a/cmd/api/user/mocks.go b/cmd/api/user/mocks.go new file mode 100644 index 0000000..036fc2b --- /dev/null +++ b/cmd/api/user/mocks.go @@ -0,0 +1,48 @@ +package user + +import ( + "context" + "time" +) + +// MockExists mocks Exists function +func MockExists(userExists bool, err error) Exists { + return func(ctx context.Context, username string) (bool, error) { + return userExists, err + } +} + +// MockInsert mocks Insert function +func MockInsert(err error) Insert { + return func(ctx context.Context, user DTO) error { + return err + } +} + +// MockDTO mocks user DTO +func MockDTO() DTO { + return DTO{ + Username: "test@test.com", + Password: "password", + } +} + +// MockDAO mocks user DAO +func MockDAO() DAO { + return DAO{ + ID: 1, + Username: "username", + Password: "password", + CreatedAt: time.Date(2006, time.January, 1, 0, 0, 0, 0, time.Local), + } +} + +// MockScanUserDAOValues mocks the properties of user DAO to be used in the Scan function +func MockScanUserDAOValues(dao DAO) []any { + return []any{ + dao.ID, + dao.Username, + dao.Password, + dao.CreatedAt, + } +} diff --git a/cmd/api/user/select.go b/cmd/api/user/select.go new file mode 100644 index 0000000..b41e1ba --- /dev/null +++ b/cmd/api/user/select.go @@ -0,0 +1,70 @@ +package user + +import ( + "context" + "errors" + + "github.com/jackc/pgx/v5" + + "ahbcc/internal/database" + "ahbcc/internal/log" +) + +type ( + // Exists validates if the given username was already registered in the database + Exists func(ctx context.Context, username string) (bool, error) + + // SelectByUsername retrieves a user by its username + SelectByUsername func(ctx context.Context, username string) (DAO, error) +) + +// MakeExists creates a new Exists +func MakeExists(db database.Connection) Exists { + const query string = ` + SELECT EXISTS ( + SELECT 1 + FROM user + WHERE username = $1 + ) + ` + + return func(ctx context.Context, username string) (bool, error) { + var applied bool + + err := db.QueryRow(ctx, query, username).Scan(&applied) + if errors.Is(err, pgx.ErrNoRows) { + log.Error(ctx, err.Error()) + return false, FailedToRetrieveIfUserAlreadyExists + } + + return applied, nil + } +} + +// MakeSelectByUsername creates a new SelectByUsername +func MakeSelectByUsername(db database.Connection) SelectByUsername { + const query string = ` + SELECT id, username, password_hash, created_at + FROM user + WHERE username = $1 + ` + + return func(ctx context.Context, username string) (DAO, error) { + var user DAO + err := db.QueryRow(ctx, query, username).Scan( + &user.ID, + &user.Username, + &user.Password, + &user.CreatedAt, + ) + if errors.Is(err, pgx.ErrNoRows) { + log.Error(ctx, err.Error()) + return DAO{}, NoUserFoundForTheGivenUsername + } else if err != nil { + log.Error(ctx, err.Error()) + return DAO{}, FailedExecuteQueryToRetrieveUser + } + + return user, nil + } +} diff --git a/cmd/api/user/select_test.go b/cmd/api/user/select_test.go new file mode 100644 index 0000000..aeb8e55 --- /dev/null +++ b/cmd/api/user/select_test.go @@ -0,0 +1,91 @@ +package user_test + +import ( + "context" + "errors" + "testing" + + "github.com/jackc/pgx/v5" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + + "ahbcc/cmd/api/user" + "ahbcc/internal/database" +) + +func TestExists_success(t *testing.T) { + mockPostgresConnection := new(database.MockPostgresConnection) + mockPgxRow := new(database.MockPgxRow) + database.MockScan(mockPgxRow, []any{true}, t) + mockPostgresConnection.On("QueryRow", mock.Anything, mock.Anything, mock.Anything).Return(mockPgxRow) + + exists := user.MakeExists(mockPostgresConnection) + + got, err := exists(context.Background(), "user") + + assert.Nil(t, err) + assert.True(t, got) + mockPostgresConnection.AssertExpectations(t) + mockPgxRow.AssertExpectations(t) +} + +func TestExists_failsWhenSelectOperationFails(t *testing.T) { + mockPostgresConnection := new(database.MockPostgresConnection) + mockPgxRow := new(database.MockPgxRow) + mockPgxRow.On("Scan", mock.Anything).Return(pgx.ErrNoRows) + mockPostgresConnection.On("QueryRow", mock.Anything, mock.Anything, mock.Anything).Return(mockPgxRow) + + exists := user.MakeExists(mockPostgresConnection) + + want := user.FailedToRetrieveIfUserAlreadyExists + _, got := exists(context.Background(), "user") + + assert.Equal(t, want, got) + mockPostgresConnection.AssertExpectations(t) + mockPgxRow.AssertExpectations(t) +} + +func TestSelectByUsername_success(t *testing.T) { + mockPostgresConnection := new(database.MockPostgresConnection) + mockPgxRow := new(database.MockPgxRow) + mockUser := user.MockDAO() + mockScanCriteriaDAOValues := user.MockScanUserDAOValues(mockUser) + database.MockScan(mockPgxRow, mockScanCriteriaDAOValues, t) + mockPostgresConnection.On("QueryRow", mock.Anything, mock.Anything, mock.Anything).Return(mockPgxRow) + + selectUserByUsername := user.MakeSelectByUsername(mockPostgresConnection) + + want := mockUser + got, err := selectUserByUsername(context.Background(), "user") + + assert.Nil(t, err) + assert.Equal(t, want, got) + mockPostgresConnection.AssertExpectations(t) + mockPgxRow.AssertExpectations(t) +} + +func TestSelectByUsername_failsWhenSelectOperationFails(t *testing.T) { + tests := []struct { + err error + expected error + }{ + {err: pgx.ErrNoRows, expected: user.NoUserFoundForTheGivenUsername}, + {err: errors.New("failed to execute select operation"), expected: user.FailedExecuteQueryToRetrieveUser}, + } + + for _, tt := range tests { + mockPostgresConnection := new(database.MockPostgresConnection) + mockPgxRow := new(database.MockPgxRow) + mockPgxRow.On("Scan", mock.Anything).Return(tt.err) + mockPostgresConnection.On("QueryRow", mock.Anything, mock.Anything, mock.Anything).Return(mockPgxRow) + + selectUserByUsername := user.MakeSelectByUsername(mockPostgresConnection) + + want := tt.expected + _, got := selectUserByUsername(context.Background(), "user") + + assert.Equal(t, want, got) + mockPostgresConnection.AssertExpectations(t) + mockPgxRow.AssertExpectations(t) + } +} diff --git a/cmd/api/users/dtos.go b/cmd/api/users/dtos.go deleted file mode 100644 index b6747ce..0000000 --- a/cmd/api/users/dtos.go +++ /dev/null @@ -1,7 +0,0 @@ -package users - -// UserDTO represents a user to be inserted into the 'users' table -type UserDTO struct { - Username string `json:"username"` - Password string `json:"password"` -} diff --git a/cmd/api/users/errors.go b/cmd/api/users/errors.go deleted file mode 100644 index 1edcf84..0000000 --- a/cmd/api/users/errors.go +++ /dev/null @@ -1,8 +0,0 @@ -package users - -import "errors" - -var ( - FailedToInsertUser = errors.New("failed to insert user") - FailedToRetrieveIfUserAlreadyExists = errors.New("failed to retrieve if user already exists") -) diff --git a/cmd/api/users/mocks.go b/cmd/api/users/mocks.go deleted file mode 100644 index 2aaa3f7..0000000 --- a/cmd/api/users/mocks.go +++ /dev/null @@ -1,25 +0,0 @@ -package users - -import "context" - -// MockUserExists mocks UserExists function -func MockUserExists(userExists bool, err error) UserExists { - return func(ctx context.Context, username string) (bool, error) { - return userExists, err - } -} - -// MockInsert mocks Insert function -func MockInsert(err error) Insert { - return func(ctx context.Context, user UserDTO) error { - return err - } -} - -// MockUserDTO mocks UserDTO -func MockUserDTO() UserDTO { - return UserDTO{ - Username: "test@test.com", - Password: "password", - } -} diff --git a/cmd/api/users/select.go b/cmd/api/users/select.go deleted file mode 100644 index a518a50..0000000 --- a/cmd/api/users/select.go +++ /dev/null @@ -1,37 +0,0 @@ -package users - -import ( - "context" - "errors" - - "github.com/jackc/pgx/v5" - - "ahbcc/internal/database" - "ahbcc/internal/log" -) - -// UserExists validates if the given username was already registered in the database -type UserExists func(ctx context.Context, username string) (bool, error) - -// MakeUserExists creates a new UserExists -func MakeUserExists(db database.Connection) UserExists { - const query string = ` - SELECT EXISTS ( - SELECT 1 - FROM users - WHERE username = $1 - ) - ` - - return func(ctx context.Context, username string) (bool, error) { - var applied bool - - err := db.QueryRow(ctx, query, username).Scan(&applied) - if errors.Is(err, pgx.ErrNoRows) { - log.Error(ctx, err.Error()) - return false, FailedToRetrieveIfUserAlreadyExists - } - - return applied, nil - } -} diff --git a/cmd/api/users/select_test.go b/cmd/api/users/select_test.go deleted file mode 100644 index 40bd056..0000000 --- a/cmd/api/users/select_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package users_test - -import ( - "context" - "testing" - - "github.com/jackc/pgx/v5" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - - "ahbcc/cmd/api/users" - "ahbcc/internal/database" -) - -func TestUserExists_success(t *testing.T) { - mockPostgresConnection := new(database.MockPostgresConnection) - mockPgxRow := new(database.MockPgxRow) - database.MockScan(mockPgxRow, []any{true}, t) - mockPostgresConnection.On("QueryRow", mock.Anything, mock.Anything, mock.Anything).Return(mockPgxRow) - - userExists := users.MakeUserExists(mockPostgresConnection) - - got, err := userExists(context.Background(), "user") - - assert.Nil(t, err) - assert.True(t, got) - mockPostgresConnection.AssertExpectations(t) - mockPgxRow.AssertExpectations(t) -} - -func TestUserExists_failsWhenSelectOperationFails(t *testing.T) { - mockPostgresConnection := new(database.MockPostgresConnection) - mockPgxRow := new(database.MockPgxRow) - mockPgxRow.On("Scan", mock.Anything).Return(pgx.ErrNoRows) - mockPostgresConnection.On("QueryRow", mock.Anything, mock.Anything, mock.Anything).Return(mockPgxRow) - - userExists := users.MakeUserExists(mockPostgresConnection) - - want := users.FailedToRetrieveIfUserAlreadyExists - _, got := userExists(context.Background(), "user") - - assert.Equal(t, want, got) - mockPostgresConnection.AssertExpectations(t) - mockPgxRow.AssertExpectations(t) -} diff --git a/migrations/006_create_users_table.sql b/migrations/006_create_users_table.sql index 5d02eea..f45ab5a 100644 --- a/migrations/006_create_users_table.sql +++ b/migrations/006_create_users_table.sql @@ -1,4 +1,4 @@ --- Create the users table +-- Create the user table CREATE TABLE IF NOT EXISTS users ( id SERIAL PRIMARY KEY, username TEXT NOT NULL, @@ -9,7 +9,7 @@ CREATE TABLE IF NOT EXISTS users ( ); -- Table indexes -SELECT create_index_if_not_exists('idx_users_username', 'users', 'username'); +SELECT create_index_if_not_exists('idx_users_username', 'user', 'username'); -- Table comments COMMENT ON TABLE users IS 'Stores user credentials and metadata'; diff --git a/migrations/007_create_users_sessions_table.sql b/migrations/007_create_users_sessions_table.sql index 1874ea3..38773a3 100644 --- a/migrations/007_create_users_sessions_table.sql +++ b/migrations/007_create_users_sessions_table.sql @@ -16,7 +16,7 @@ SELECT create_index_if_not_exists('idx_users_sessions_token', 'users_sessions', -- Table comments COMMENT ON TABLE users_sessions IS 'Stores active sessions with token information'; COMMENT ON COLUMN users_sessions.id IS 'Auto-incrementing ID of the session, agnostic to business logic'; -COMMENT ON COLUMN users_sessions.user_id IS 'Foreign key referencing users table'; +COMMENT ON COLUMN users_sessions.user_id IS 'Foreign key referencing user table'; COMMENT ON COLUMN users_sessions.token IS 'Bearer token for session authentication'; COMMENT ON COLUMN users_sessions.expires_at IS 'Expiration time of the session token'; COMMENT ON COLUMN users_sessions.created_at IS 'Timestamp of when the session was created'; \ No newline at end of file diff --git a/migrations/008_create_categorized_tweets_table.sql b/migrations/008_create_categorized_tweets_table.sql index 03351b6..7ca77ad 100644 --- a/migrations/008_create_categorized_tweets_table.sql +++ b/migrations/008_create_categorized_tweets_table.sql @@ -14,7 +14,7 @@ CREATE INDEX idx_categorized_tweets_tweet_id ON categorized_tweets(tweet_id); CREATE INDEX idx_categorized_tweets_user_id ON categorized_tweets(user_id); -- Table comments -COMMENT ON TABLE categorized_tweets IS 'Contains the categorization of tweets by users for adverse behavior'; +COMMENT ON TABLE categorized_tweets IS 'Contains the categorization of tweets by user for adverse behavior'; COMMENT ON COLUMN categorized_tweets.id IS 'Auto-incrementing ID of the categorization record, agnostic to business logic'; COMMENT ON COLUMN categorized_tweets.tweet_id IS 'Foreign key referencing the ID of the tweet'; COMMENT ON COLUMN categorized_tweets.user_id IS 'Foreign key referencing the ID of the user who categorized the tweet';