diff --git a/Makefile b/Makefile index dfde1a2..6db71db 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ migrateup: migrate -path db/migrations -database "${DB_TYPE}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}_test?sslmode=disable" -verbose up migratedown: - migrate -path db/migrations -database "${DB_TYPE}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=disable" -verbose down $N - migrate -path db/migrations -database "${DB_TYPE}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}_test?sslmode=disable" -verbose down $N + migrate -path db/migrations -database "${DB_TYPE}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}?sslmode=disable" -verbose down $n + migrate -path db/migrations -database "${DB_TYPE}://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}_test?sslmode=disable" -verbose down $n seed: ./import_csv.sh diff --git a/db/csv_seeder/locations.csv b/db/csv_seeder/locations.csv index 9a3cbcd..329bf28 100644 --- a/db/csv_seeder/locations.csv +++ b/db/csv_seeder/locations.csv @@ -1,10 +1,10 @@ -id#address#name#submitted_by#thumbnail#regency_id#google_maps_link -1#Jalan Raya Beside the bridge Ubud#Murni’s Warung#1#https://cdn.discordapp.com/attachments/743422487882104837/1150972798320267304/image.png#5104#https://www.google.com/maps/place/Murni's+Warung/@-8.5048696,115.2553417,19z/data=!4m6!3m5!1s0x2dd23d3e0ffaa071:0xf2fa69b4cb211e41!8m2!3d-8.5051184!4d115.2547196!16s%2Fg%2F1tdsmcq7?entry=ttu -2#Jl.Taman Wijaya Kusuma Ps. Baru Kecamatan Sawah Besar#Masjid Istiqlal#1#https://dynamic-media-cdn.tripadvisor.com/media/photo-o/04/11/31/33/istiqlal-mosque-mesjid.jpg?w=500&h=-1&s=1#3173#https://www.google.com/maps/place/Masjid+Istiqlal/@-6.1703155,106.8308434,19z/data=!4m15!1m7!3m6!1s0x2e69f5ce68b5e01d:0xcafaf042d5840c6c!2sMasjid+Istiqlal!8m2!3d-6.17017!4d106.83139!16zL20vMDRzam1q!3m6!1s0x2e69f5ce68b5e01d:0xcafaf042d5840c6c!8m2!3d-6.17017!4d106.83139!15sCg9tYXNqaWQgaXN0aXFsYWxaESIPbWFzamlkIGlzdGlxbGFskgEGbW9zcXVl4AEA!16zL20vMDRzam1q?entry=ttu -3#Jl. Mayjend Sungkono no. 89#Hotel Ciputra World Surabaya#1#https://lh5.googleusercontent.com/p/AF1QipOvHDO-M6riRoqBrWU3MskhwL_bue8JmN9faq7Q=w500-h500-k-no#3578#https://www.google.com/maps/place/Ciputra+World+Hotel+Surabaya/@-7.2923061,112.7191552,15z/data=!4m2!3m1!1s0x0:0x736a9c49dcc2ac42?sa=X&ved=2ahUKEwjJlbf8gqSBAxWtzzgGHUIkBFYQ_BJ6BAgVEAA&ved=2ahUKEwjJlbf8gqSBAxWtzzgGHUIkBFYQ_BJ6BAgjEAc -4#Jl. Taman Safari No.101 . B Cibeureum Kec. Cisarua#Club Huis#1#https://media-cdn.tripadvisor.com/media/photo-o/0d/6a/5d/63/our-peaceful-backyard.jpg#3201#https://www.google.com/maps/place/Club+Huis/@-6.7027857,106.9453741,17z/data=!3m1!4b1!4m6!3m5!1s0x2e69b679d7a09e01:0xf9fc2df396f09977!8m2!3d-6.7027857!4d106.947949!16s%2Fg%2F11c57lh8ky?entry=ttu -5#Desa Tambakrejo Kecamatan Sumbermanjing Wetan#Pulau Sempu#1#https://dynamic-media-cdn.tripadvisor.com/media/photo-o/11/3b/06/a5/pulau-sempu.jpg?w=500&h=-1&s=1#3507#https://www.google.com/maps/place/Pulau+Sempu/@-8.446621,112.6746143,14z/data=!3m1!4b1!4m6!3m5!1s0x2dd60120edbc901f:0x8efd89687a308993!8m2!3d-8.4428564!4d112.6973355!16s%2Fm%2F0r8k540?entry=ttu -6#Jl. Bukit Golf I BSD Sektor VI Lengkong Karya Kec. Serpong Utara#Damai Indah Golf#1#https://lh3.googleusercontent.com/p/AF1QipN5Z-0J6vIfIO6gqPO0z5HDWlNKqp0t816XIJPS=s680-w500-h500#3674#https://www.google.com/maps/place/Damai+Indah+Golf+-+BSD+Course/@-6.2815644,106.6496566,17z/data=!3m1!4b1!4m6!3m5!1s0x2e69fb152983d973:0x89e58e219f8b93ef!8m2!3d-6.2815644!4d106.6522315!16s%2Fg%2F11c54c9r94?entry=ttu -7#Jl. P. Mangkubumi No.72A Cokrodiningratan Kec. Jetis#Hotel Tentrem Yogyakarta#1#https://cdn.discordapp.com/attachments/743422487882104837/1150987888553623653/image.png#3471#https://www.google.com/maps?q=Hotel+Tentrem+Yogyakarta&source=lmns&entry=mc&bih=1115&biw=2124&hl=en-US&sa=X&ved=2ahUKEwjjl-HHiKSBAxUu5jgGHTU3BiwQ0pQJKAJ6BAgBEAY -8#Moluo Kec.Kwandang#Pulau Saronde Gorontalo#1#https://dynamic-media-cdn.tripadvisor.com/media/photo-o/0d/ec/58/21/saronde-island-a-place.jpg?w=700&h=-1&s=1#7505#https://www.google.com/maps/place/Pulau+Saronde+Gorontalo/@0.9263376,122.8613201,17z/data=!3m1!4b1!4m6!3m5!1s0x32795bf34dff4467:0xa8beb2a832ae8176!8m2!3d0.9263376!4d122.863895!16s%2Fg%2F11l241cc1d?hl=id&entry=ttu -9#Dusun Katiet Desa Bosua Kecamatan Sipora#Pantai Katiet#1#https://dynamic-media-cdn.tripadvisor.com/media/photo-o/1a/d7/fe/f4/mentawai-islands.jpg?w=500&h=-1&s=1#1301#https://www.google.com/maps/place/Katiet,+Bosua,+Sipora+Selatan,+Mentawai+Islands+Regency,+West+Sumatra/@-2.375793,99.848187,15z/data=!3m1!4b1!4m6!3m5!1s0x2fd27efa8363912f:0x8c9c19bd76cba179!8m2!3d-2.375793!4d99.848187!16s%2Fg%2F1tcwz0mt?hl=en-US&entry=ttu \ No newline at end of file +id,address,name,submitted_by,thumbnail,regency_id,google_maps_link,approved_by +1#Jalan Raya Beside the bridge Ubud#Murni’s Warung#1#https://cdn.discordapp.com/attachments/743422487882104837/1150972798320267304/image.png#5104#https://www.google.com/maps/place/Murni's+Warung/@-8.5048696,115.2553417,19z/data=!4m6!3m5!1s0x2dd23d3e0ffaa071:0xf2fa69b4cb211e41!8m2!3d-8.5051184!4d115.2547196!16s%2Fg%2F1tdsmcq7?entry=ttu#1 +2#Jl.Taman Wijaya Kusuma Ps. Baru Kecamatan Sawah Besar#Masjid Istiqlal#1#https://dynamic-media-cdn.tripadvisor.com/media/photo-o/04/11/31/33/istiqlal-mosque-mesjid.jpg?w=500&h=-1&s=1#3173#https://www.google.com/maps/place/Masjid+Istiqlal/@-6.1703155,106.8308434,19z/data=!4m15!1m7!3m6!1s0x2e69f5ce68b5e01d:0xcafaf042d5840c6c!2sMasjid+Istiqlal!8m2!3d-6.17017!4d106.83139!16zL20vMDRzam1q!3m6!1s0x2e69f5ce68b5e01d:0xcafaf042d5840c6c!8m2!3d-6.17017!4d106.83139!15sCg9tYXNqaWQgaXN0aXFsYWxaESIPbWFzamlkIGlzdGlxbGFskgEGbW9zcXVl4AEA!16zL20vMDRzam1q?entry=ttu#1 +3#Jl. Mayjend Sungkono no. 89#Hotel Ciputra World Surabaya#1#https://lh5.googleusercontent.com/p/AF1QipOvHDO-M6riRoqBrWU3MskhwL_bue8JmN9faq7Q=w500-h500-k-no#3578#https://www.google.com/maps/place/Ciputra+World+Hotel+Surabaya/@-7.2923061,112.7191552,15z/data=!4m2!3m1!1s0x0:0x736a9c49dcc2ac42?sa=X&ved=2ahUKEwjJlbf8gqSBAxWtzzgGHUIkBFYQ_BJ6BAgVEAA&ved=2ahUKEwjJlbf8gqSBAxWtzzgGHUIkBFYQ_BJ6BAgjEAc#1 +4#Jl. Taman Safari No.101 . B Cibeureum Kec. Cisarua#Club Huis#1#https://media-cdn.tripadvisor.com/media/photo-o/0d/6a/5d/63/our-peaceful-backyard.jpg#3201#https://www.google.com/maps/place/Club+Huis/@-6.7027857,106.9453741,17z/data=!3m1!4b1!4m6!3m5!1s0x2e69b679d7a09e01:0xf9fc2df396f09977!8m2!3d-6.7027857!4d106.947949!16s%2Fg%2F11c57lh8ky?entry=ttu#1 +5#Desa Tambakrejo Kecamatan Sumbermanjing Wetan#Pulau Sempu#1#https://dynamic-media-cdn.tripadvisor.com/media/photo-o/11/3b/06/a5/pulau-sempu.jpg?w=500&h=-1&s=1#3507#https://www.google.com/maps/place/Pulau+Sempu/@-8.446621,112.6746143,14z/data=!3m1!4b1!4m6!3m5!1s0x2dd60120edbc901f:0x8efd89687a308993!8m2!3d-8.4428564!4d112.6973355!16s%2Fm%2F0r8k540?entry=ttu#1 +6#Jl. Bukit Golf I BSD Sektor VI Lengkong Karya Kec. Serpong Utara#Damai Indah Golf#1#https://lh3.googleusercontent.com/p/AF1QipN5Z-0J6vIfIO6gqPO0z5HDWlNKqp0t816XIJPS=s680-w500-h500#3674#https://www.google.com/maps/place/Damai+Indah+Golf+-+BSD+Course/@-6.2815644,106.6496566,17z/data=!3m1!4b1!4m6!3m5!1s0x2e69fb152983d973:0x89e58e219f8b93ef!8m2!3d-6.2815644!4d106.6522315!16s%2Fg%2F11c54c9r94?entry=ttu#1 +7#Jl. P. Mangkubumi No.72A Cokrodiningratan Kec. Jetis#Hotel Tentrem Yogyakarta#1#https://cdn.discordapp.com/attachments/743422487882104837/1150987888553623653/image.png#3471#https://www.google.com/maps?q=Hotel+Tentrem+Yogyakarta&source=lmns&entry=mc&bih=1115&biw=2124&hl=en-US&sa=X&ved=2ahUKEwjjl-HHiKSBAxUu5jgGHTU3BiwQ0pQJKAJ6BAgBEAY#1 +8#Moluo Kec.Kwandang#Pulau Saronde Gorontalo#1#https://dynamic-media-cdn.tripadvisor.com/media/photo-o/0d/ec/58/21/saronde-island-a-place.jpg?w=700&h=-1&s=1#7505#https://www.google.com/maps/place/Pulau+Saronde+Gorontalo/@0.9263376,122.8613201,17z/data=!3m1!4b1!4m6!3m5!1s0x32795bf34dff4467:0xa8beb2a832ae8176!8m2!3d0.9263376!4d122.863895!16s%2Fg%2F11l241cc1d?hl=id&entry=ttu#1 +9#Dusun Katiet Desa Bosua Kecamatan Sipora#Pantai Katiet#1#https://dynamic-media-cdn.tripadvisor.com/media/photo-o/1a/d7/fe/f4/mentawai-islands.jpg?w=500&h=-1&s=1#1301#https://www.google.com/maps/place/Katiet,+Bosua,+Sipora+Selatan,+Mentawai+Islands+Regency,+West+Sumatra/@-2.375793,99.848187,15z/data=!3m1!4b1!4m6!3m5!1s0x2fd27efa8363912f:0x8c9c19bd76cba179!8m2!3d-2.375793!4d99.848187!16s%2Fg%2F1tcwz0mt?hl=en-US&entry=ttu#1 \ No newline at end of file diff --git a/db/migrations/000001_init_schema.up.sql b/db/migrations/000001_init_schema.up.sql index 9bc17fe..e5672fb 100644 --- a/db/migrations/000001_init_schema.up.sql +++ b/db/migrations/000001_init_schema.up.sql @@ -12,6 +12,7 @@ CREATE TABLE users( "is_admin" boolean, "is_critics" boolean, "is_verified" boolean, + "is_active" boolean, "social_media" jsonb, "created_at" timestamp default(now()), "updated_at" timestamp default(now()) @@ -80,7 +81,7 @@ CREATE TABLE locations( "google_maps_link" varchar, "submitted_by" integer references "users"("id") not null, "total_visited" integer, - "thumbnail" varchar not null, + "thumbnail" varchar, "regency_id" smallint references "regencies"("id") not null, "is_deleted" boolean, "created_at" timestamp default(now()), diff --git a/db/migrations/000002_add_approvedby_in_locations_table.down.sql b/db/migrations/000002_add_approvedby_in_locations_table.down.sql new file mode 100644 index 0000000..5ad6ad4 --- /dev/null +++ b/db/migrations/000002_add_approvedby_in_locations_table.down.sql @@ -0,0 +1,2 @@ +ALTER TABLE locations DROP COLUMN IF EXISTS approved_by; +ALTER TABLE locations DROP COLUMN IF EXISTS approved_at; \ No newline at end of file diff --git a/db/migrations/000002_add_approvedby_in_locations_table.up.sql b/db/migrations/000002_add_approvedby_in_locations_table.up.sql new file mode 100644 index 0000000..bc21957 --- /dev/null +++ b/db/migrations/000002_add_approvedby_in_locations_table.up.sql @@ -0,0 +1,2 @@ +ALTER TABLE locations ADD column approved_by int references "users"("id"); +ALTER TABLE locations ADD column approved_at timestamp; \ No newline at end of file diff --git a/db/mock/store.go b/db/mock/store.go index 8bc1c5d..2c059a9 100644 --- a/db/mock/store.go +++ b/db/mock/store.go @@ -35,6 +35,20 @@ func (m *MockStore) EXPECT() *MockStoreMockRecorder { return m.recorder } +// CreateLocation mocks base method. +func (m *MockStore) CreateLocation(arg0 context.Context, arg1 db.CreateLocationParams) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "CreateLocation", arg0, arg1) + ret0, _ := ret[0].(error) + return ret0 +} + +// CreateLocation indicates an expected call of CreateLocation. +func (mr *MockStoreMockRecorder) CreateLocation(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateLocation", reflect.TypeOf((*MockStore)(nil).CreateLocation), arg0, arg1) +} + // CreateUser mocks base method. func (m *MockStore) CreateUser(arg0 context.Context, arg1 db.CreateUserParams) (db.User, error) { m.ctrl.T.Helper() @@ -50,6 +64,36 @@ func (mr *MockStoreMockRecorder) CreateUser(arg0, arg1 interface{}) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateUser", reflect.TypeOf((*MockStore)(nil).CreateUser), arg0, arg1) } +// GetListLocations mocks base method. +func (m *MockStore) GetListLocations(arg0 context.Context, arg1 db.GetListLocationsParams) ([]db.Location, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetListLocations", arg0, arg1) + ret0, _ := ret[0].([]db.Location) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetListLocations indicates an expected call of GetListLocations. +func (mr *MockStoreMockRecorder) GetListLocations(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetListLocations", reflect.TypeOf((*MockStore)(nil).GetListLocations), arg0, arg1) +} + +// GetLocation mocks base method. +func (m *MockStore) GetLocation(arg0 context.Context, arg1 int32) (db.Location, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "GetLocation", arg0, arg1) + ret0, _ := ret[0].(db.Location) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// GetLocation indicates an expected call of GetLocation. +func (mr *MockStoreMockRecorder) GetLocation(arg0, arg1 interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetLocation", reflect.TypeOf((*MockStore)(nil).GetLocation), arg0, arg1) +} + // UpdatePassword mocks base method. func (m *MockStore) UpdatePassword(arg0 context.Context, arg1 db.UpdatePasswordParams) error { m.ctrl.T.Helper() diff --git a/db/queries/locations.sql b/db/queries/locations.sql index e69de29..e7923cb 100644 --- a/db/queries/locations.sql +++ b/db/queries/locations.sql @@ -0,0 +1,19 @@ +-- name: GetListLocations :many +SELECT * FROM locations +LIMIT $1 +OFFSET $2; + +-- name: GetLocation :one +SELECT * FROM locations +WHERE id = $1; + +-- name: CreateLocation :exec +INSERT INTO locations( + address, + name, + submitted_by, + regency_id, + google_maps_link +) values ( + $1, $2, $3, $4, $5 +); \ No newline at end of file diff --git a/db/sqlc/locations.sql.go b/db/sqlc/locations.sql.go new file mode 100644 index 0000000..e9a028a --- /dev/null +++ b/db/sqlc/locations.sql.go @@ -0,0 +1,116 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.20.0 +// source: locations.sql + +package db + +import ( + "context" + "database/sql" +) + +const createLocation = `-- name: CreateLocation :exec +INSERT INTO locations( + address, + name, + submitted_by, + regency_id, + google_maps_link +) values ( + $1, $2, $3, $4, $5 +) +` + +type CreateLocationParams struct { + Address string `json:"address"` + Name string `json:"name"` + SubmittedBy int32 `json:"submitted_by"` + RegencyID int16 `json:"regency_id"` + GoogleMapsLink sql.NullString `json:"google_maps_link"` +} + +func (q *Queries) CreateLocation(ctx context.Context, arg CreateLocationParams) error { + _, err := q.db.ExecContext(ctx, createLocation, + arg.Address, + arg.Name, + arg.SubmittedBy, + arg.RegencyID, + arg.GoogleMapsLink, + ) + return err +} + +const getListLocations = `-- name: GetListLocations :many +SELECT id, address, name, google_maps_link, submitted_by, total_visited, thumbnail, regency_id, is_deleted, created_at, updated_at, approved_by, approved_at FROM locations +LIMIT $1 +OFFSET $2 +` + +type GetListLocationsParams struct { + Limit int32 `json:"limit"` + Offset int32 `json:"offset"` +} + +func (q *Queries) GetListLocations(ctx context.Context, arg GetListLocationsParams) ([]Location, error) { + rows, err := q.db.QueryContext(ctx, getListLocations, arg.Limit, arg.Offset) + if err != nil { + return nil, err + } + defer rows.Close() + items := []Location{} + for rows.Next() { + var i Location + if err := rows.Scan( + &i.ID, + &i.Address, + &i.Name, + &i.GoogleMapsLink, + &i.SubmittedBy, + &i.TotalVisited, + &i.Thumbnail, + &i.RegencyID, + &i.IsDeleted, + &i.CreatedAt, + &i.UpdatedAt, + &i.ApprovedBy, + &i.ApprovedAt, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getLocation = `-- name: GetLocation :one +SELECT id, address, name, google_maps_link, submitted_by, total_visited, thumbnail, regency_id, is_deleted, created_at, updated_at, approved_by, approved_at FROM locations +WHERE id = $1 +` + +func (q *Queries) GetLocation(ctx context.Context, id int32) (Location, error) { + row := q.db.QueryRowContext(ctx, getLocation, id) + var i Location + err := row.Scan( + &i.ID, + &i.Address, + &i.Name, + &i.GoogleMapsLink, + &i.SubmittedBy, + &i.TotalVisited, + &i.Thumbnail, + &i.RegencyID, + &i.IsDeleted, + &i.CreatedAt, + &i.UpdatedAt, + &i.ApprovedBy, + &i.ApprovedAt, + ) + return i, err +} diff --git a/db/sqlc/models.go b/db/sqlc/models.go index bb21739..704eace 100644 --- a/db/sqlc/models.go +++ b/db/sqlc/models.go @@ -126,8 +126,8 @@ type Comment struct { type Location struct { ID int32 `json:"id"` - Address sql.NullString `json:"address"` - Name sql.NullString `json:"name"` + Address string `json:"address"` + Name string `json:"name"` GoogleMapsLink sql.NullString `json:"google_maps_link"` SubmittedBy int32 `json:"submitted_by"` TotalVisited sql.NullInt32 `json:"total_visited"` @@ -136,6 +136,8 @@ type Location struct { IsDeleted sql.NullBool `json:"is_deleted"` CreatedAt sql.NullTime `json:"created_at"` UpdatedAt sql.NullTime `json:"updated_at"` + ApprovedBy sql.NullInt32 `json:"approved_by"` + ApprovedAt sql.NullTime `json:"approved_at"` } type LocationImage struct { @@ -204,6 +206,7 @@ type User struct { IsAdmin sql.NullBool `json:"is_admin"` IsCritics sql.NullBool `json:"is_critics"` IsVerified sql.NullBool `json:"is_verified"` + IsActive sql.NullBool `json:"is_active"` SocialMedia pqtype.NullRawMessage `json:"social_media"` CreatedAt sql.NullTime `json:"created_at"` UpdatedAt sql.NullTime `json:"updated_at"` diff --git a/db/sqlc/querier.go b/db/sqlc/querier.go index c1a8c45..1c8f530 100644 --- a/db/sqlc/querier.go +++ b/db/sqlc/querier.go @@ -9,7 +9,10 @@ import ( ) type Querier interface { + CreateLocation(ctx context.Context, arg CreateLocationParams) error CreateUser(ctx context.Context, arg CreateUserParams) (User, error) + GetListLocations(ctx context.Context, arg GetListLocationsParams) ([]Location, error) + GetLocation(ctx context.Context, id int32) (Location, error) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error) } diff --git a/db/sqlc/users.sql.go b/db/sqlc/users.sql.go index 649ac34..6dbb453 100644 --- a/db/sqlc/users.sql.go +++ b/db/sqlc/users.sql.go @@ -15,7 +15,7 @@ INSERT INTO users ( username, password ) VALUES ($1, $2) -RETURNING id, email, username, password, avatar_picture, google_sign_in_payload, banned_at, banned_until, ban_reason, is_permaban, is_admin, is_critics, is_verified, social_media, created_at, updated_at +RETURNING id, email, username, password, avatar_picture, google_sign_in_payload, banned_at, banned_until, ban_reason, is_permaban, is_admin, is_critics, is_verified, is_active, social_media, created_at, updated_at ` type CreateUserParams struct { @@ -40,6 +40,7 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, e &i.IsAdmin, &i.IsCritics, &i.IsVerified, + &i.IsActive, &i.SocialMedia, &i.CreatedAt, &i.UpdatedAt, @@ -71,7 +72,7 @@ SET avatar_picture = COALESCE($3, avatar_picture) WHERE id = $4 -RETURNING id, email, username, password, avatar_picture, google_sign_in_payload, banned_at, banned_until, ban_reason, is_permaban, is_admin, is_critics, is_verified, social_media, created_at, updated_at +RETURNING id, email, username, password, avatar_picture, google_sign_in_payload, banned_at, banned_until, ban_reason, is_permaban, is_admin, is_critics, is_verified, is_active, social_media, created_at, updated_at ` type UpdateUserParams struct { @@ -103,6 +104,7 @@ func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, e &i.IsAdmin, &i.IsCritics, &i.IsVerified, + &i.IsActive, &i.SocialMedia, &i.CreatedAt, &i.UpdatedAt, diff --git a/import_csv.sh b/import_csv.sh index 131c83b..5d6944a 100755 --- a/import_csv.sh +++ b/import_csv.sh @@ -5,12 +5,26 @@ sudo -u postgres psql \ -c '\copy regions(id, region_name) FROM '"'/tmp/regions.csv'"' DELIMITER '"','"' CSV HEADER;' \ -c '\copy provinces(id, province_name, region_id) FROM '"'/tmp/provinsi.csv'"' DELIMITER '"','"' CSV HEADER;' \ -c '\copy regencies(id, province_id, regency_name) FROM '"'/tmp/kabupaten.csv'"' DELIMITER '"','"' CSV HEADER;' \ - -c '\copy locations(id,address,name,submitted_by,thumbnail,regency_id,google_maps_link) FROM '"'/tmp/locations.csv'"' DELIMITER '"'#'"' CSV HEADER;' \ + -c '\copy locations(id,address,name,submitted_by,thumbnail,regency_id,google_maps_link,approved_by) FROM '"'/tmp/locations.csv'"' DELIMITER '"'#'"' CSV HEADER;' \ -d hiling_dev && sudo -u postgres psql \ -c '\copy users(id,username,password) FROM '"'/tmp/user.csv'"' DELIMITER '"','"' CSV HEADER;' \ -c '\copy regions(id, region_name) FROM '"'/tmp/regions.csv'"' DELIMITER '"','"' CSV HEADER;' \ -c '\copy provinces(id, province_name, region_id) FROM '"'/tmp/provinsi.csv'"' DELIMITER '"','"' CSV HEADER;' \ -c '\copy regencies(id, province_id, regency_name) FROM '"'/tmp/kabupaten.csv'"' DELIMITER '"','"' CSV HEADER;' \ - -c '\copy locations(id,address,name,submitted_by,thumbnail,regency_id,google_maps_link) FROM '"'/tmp/locations.csv'"' DELIMITER '"'#'"' CSV HEADER;' \ + -c '\copy locations(id,address,name,submitted_by,thumbnail,regency_id,google_maps_link,approved_by) FROM '"'/tmp/locations.csv'"' DELIMITER '"'#'"' CSV HEADER;' \ -d hiling_dev_test + +# FIXING SEQUENCES AFTER SEEDING +sudo -u postgres psql \ + -c 'SELECT setval('"'locations_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'locations_id_seq'"'))-1 FROM locations))' \ + -d hiling_dev_test && +sudo -u postgres psql \ + -c 'SELECT setval('"'users_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'users_id_seq'"'))-1 FROM users))' \ + -d hiling_dev_test +sudo -u postgres psql \ + -c 'SELECT setval('"'locations_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'locations_id_seq'"'))-1 FROM locations))' \ + -d hiling_dev && +sudo -u postgres psql \ + -c 'SELECT setval('"'users_id_seq'"',(SELECT GREATEST(MAX(id)+1,nextval('"'users_id_seq'"'))-1 FROM users))' \ + -d hiling_dev