From e8e09c610f8d5a7d9389317a9eab2efd620f1c3f Mon Sep 17 00:00:00 2001 From: Sumita Canopas Date: Fri, 6 Oct 2023 19:12:07 +0530 Subject: [PATCH] Migrate mysql db to postgres --- .github/workflows/build.yml | 11 ++++---- blogs/go.mod | 2 +- blogs/go.sum | 1 - contact/go.mod | 2 +- db/go.mod | 2 +- db/sql.go | 17 ++++++++----- go.mod | 2 +- go.sum | 1 - infrastructure/backend.yml | 10 ++++---- jobs/go.mod | 2 +- jobs/jobs.go | 51 +++++++++++++++---------------------- jobs/jobs_test.go | 2 +- leave/go.mod | 1 + notification/go.mod | 2 +- sitemap/go.mod | 2 +- utils/go.mod | 2 +- utils/test.go | 41 +++++++++++++++++++---------- 17 files changed, 80 insertions(+), 71 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0dfd2c3b0..d676a5d44 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,13 +5,14 @@ jobs: run_tests: runs-on: ubuntu-latest services: - mysql: - image: mysql:8.0 + postgres: + image: postgres:15 ports: - - 3306:3306 + - 5432:5432 env: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: website_admin_test + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: website_admin_test steps: - name: Checkout uses: actions/checkout@v2.3.3 diff --git a/blogs/go.mod b/blogs/go.mod index 52f0fa0e6..86386835c 100644 --- a/blogs/go.mod +++ b/blogs/go.mod @@ -26,7 +26,6 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.11.2 // indirect - github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/goccy/go-json v0.10.0 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -39,6 +38,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.0.9 // indirect github.com/leodido/go-urn v1.2.1 // indirect + github.com/lib/pq v1.2.0 // indirect github.com/mattn/go-isatty v0.0.17 // indirect github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/blogs/go.sum b/blogs/go.sum index 87e9f2723..29e832016 100644 --- a/blogs/go.sum +++ b/blogs/go.sum @@ -261,7 +261,6 @@ github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= diff --git a/contact/go.mod b/contact/go.mod index e135aab91..db0963b90 100644 --- a/contact/go.mod +++ b/contact/go.mod @@ -24,7 +24,6 @@ require ( github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/validator/v10 v10.10.0 // indirect - github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/goccy/go-json v0.9.7 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -36,6 +35,7 @@ require ( github.com/jmoiron/sqlx v1.3.5 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/leodido/go-urn v1.2.1 // indirect + github.com/lib/pq v1.2.0 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/db/go.mod b/db/go.mod index 26a73d87c..43ee3f97a 100644 --- a/db/go.mod +++ b/db/go.mod @@ -3,8 +3,8 @@ module db go 1.20 require ( - github.com/go-sql-driver/mysql v1.6.0 github.com/jmoiron/sqlx v1.3.5 + github.com/lib/pq v1.2.0 github.com/sirupsen/logrus v1.9.0 ) diff --git a/db/sql.go b/db/sql.go index 84e7d3bf4..f85e77480 100644 --- a/db/sql.go +++ b/db/sql.go @@ -5,9 +5,9 @@ import ( "strings" "time" - _ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx/reflectx" + _ "github.com/lib/pq" log "github.com/sirupsen/logrus" ) @@ -19,13 +19,13 @@ func NewSql() *sqlx.DB { username := os.Getenv("DB_USERNAME") if username == "" { - username = "root" + username = "postgres" } password := os.Getenv("DB_PASSWORD") if password == "" { - password = "root" + password = "postgres" } host := os.Getenv("DB_HOST") @@ -37,16 +37,21 @@ func NewSql() *sqlx.DB { port := os.Getenv("DB_PORT") if port == "" { - port = "3306" + port = "5432" } name := os.Getenv("DB_NAME") if name == "" { - name = "website_admin" + name = "postgres" } - db = sqlx.MustConnect("mysql", username+":"+password+"@("+host+":"+port+")/"+name) + sslmode := "require" + if os.Getenv("DB_ENV") != "test" { + sslmode = "disable" + } + + db = sqlx.MustConnect("postgres", "postgres://"+username+":"+password+"@"+host+":"+port+"?sslmode="+sslmode+"") db.Mapper = reflectx.NewMapperFunc("json", strings.ToLower) db.SetConnMaxLifetime(time.Minute * 1) diff --git a/go.mod b/go.mod index bc1e6b9d6..43092d15a 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,6 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.15.0 // indirect - github.com/go-sql-driver/mysql v1.7.1 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect @@ -65,6 +64,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/leodido/go-urn v1.2.4 // indirect + github.com/lib/pq v1.2.0 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/go.sum b/go.sum index eb2da2592..7b4c1f0a1 100644 --- a/go.sum +++ b/go.sum @@ -69,7 +69,6 @@ github.com/go-playground/validator/v10 v10.15.0 h1:nDU5XeOKtB3GEa+uB7GNYwhVKsgjA github.com/go-playground/validator/v10 v10.15.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= -github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= diff --git a/infrastructure/backend.yml b/infrastructure/backend.yml index 7841b61c9..15806f7d6 100644 --- a/infrastructure/backend.yml +++ b/infrastructure/backend.yml @@ -33,19 +33,19 @@ Parameters: Description: aws-region. DbUsername: Type: String - Description: Mysql database username. + Description: Postgres database username. DbPassword: Type: String - Description: Mysql database password. + Description: Postgres database password. DbHost: Type: String - Description: Mysql database host. + Description: Postgres database host. DbPort: Type: String - Description: Mysql database port. + Description: Postgres database port. DbName: Type: String - Description: Mysql database name. + Description: Postgres database name. RecaptchaConfigJSONBase64: Type: String Description: Recaptcha enterprise credentials in base64 format diff --git a/jobs/go.mod b/jobs/go.mod index f89ed4dc5..d834d6da6 100644 --- a/jobs/go.mod +++ b/jobs/go.mod @@ -27,7 +27,6 @@ require ( github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/validator/v10 v10.10.0 // indirect - github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/goccy/go-json v0.9.7 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -38,6 +37,7 @@ require ( github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/leodido/go-urn v1.2.1 // indirect + github.com/lib/pq v1.2.0 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/jobs/jobs.go b/jobs/jobs.go index 180ed258a..3b9097ed5 100644 --- a/jobs/jobs.go +++ b/jobs/jobs.go @@ -96,11 +96,14 @@ func (repository *CareerRepository) GetCareers() ([]Career, error) { careers := []Career{} - err := repository.Db.Select(&careers, "SELECT id, title, summary, description, button_name, qualification, employment_type,"+ - "base_salary, experience, is_active, skills, total_openings,"+ - "responsibilities, icon_name, unique_id, seo_title, seo_description,"+ - "apply_seo_title, apply_seo_description, `index` "+ - "FROM jobs WHERE is_active = 1 ORDER BY `index`") + err := repository.Db.Select(&careers, "SELECT j.id, j.title, j.summary, j.description, j.button_name, j.qualification, "+ + "j.employment_type, j.base_salary, j.experience, j.is_active, j.skills, "+ + "j.total_openings, j.responsibilities, i.value as icon_name, "+ + "j.unique_id, j.seo_title, j.seo_description, "+ + "j.apply_seo_title, j.apply_seo_description, j.index "+ + "FROM jobs j JOIN job_icons i ON j.icon_name = i.id "+ + "WHERE j.is_active = true "+ + "ORDER BY j.index") return careers, err } @@ -111,14 +114,14 @@ func (repository *CareerRepository) CareerById(c *gin.Context) { id := c.Param("unique_id") - err := repository.Db.Get(&career, "SELECT id, title, summary, description, button_name, qualification, "+ - "employment_type, base_salary, experience, is_active, skills, "+ - "total_openings, responsibilities, icon_name, "+ - "unique_id, seo_title, seo_description, "+ - "apply_seo_title, apply_seo_description, `index` "+ - "FROM jobs "+ - "WHERE unique_id = ? AND is_active = 1 "+ - "ORDER BY `index`", id) + err := repository.Db.Get(&career, "SELECT j.id, j.title, j.summary, j.description, j.button_name, j.qualification, "+ + "j.employment_type, j.base_salary, j.experience, j.is_active, j.skills, "+ + "j.total_openings, j.responsibilities, i.value as icon_name, "+ + "j.unique_id, j.seo_title, j.seo_description, "+ + "j.apply_seo_title, j.apply_seo_description, j.index "+ + "FROM jobs j JOIN job_icons i ON j.icon_name = i.id "+ + "WHERE j.unique_id = '"+id+"' AND j.is_active = true "+ + "ORDER BY j.index") if err != nil { log.Error(err) @@ -189,33 +192,21 @@ func (repository *CareerRepository) InsertJobApplication(input JobsApplicationsD return err } - stmt, err := repository.Db.Prepare(`INSERT INTO job_applications (name, email, phone, place, reference, resumeURL, position, message, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`) + var responseID int + err = repository.Db.QueryRow("INSERT INTO job_applications (name, email, phone, place, reference, resumeurl, position, message, status, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING id", input.Name, input.Email, input.Phone, input.Place, input.References, resumeURL, input.JobTitle, input.Message, 1, time.Now(), time.Now()).Scan(&responseID) if err != nil { - log.Error(err) + log.Error("responseID: ", err) return err } - defer stmt.Close() - query, err := repository.Db.Prepare(`INSERT INTO job_applicant_statuses (applicant_id, status, ` + "`index`" + `, rejection_with_mail, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?)`) + query, err := repository.Db.Prepare("INSERT INTO job_applicant_statuses (applicant_id, status, index, rejection_with_mail, created_at, updated_at) VALUES ($1, $2, $3, $4, $5, $6)") if err != nil { - log.Error(err) + log.Error("query: ", err) return err } defer query.Close() - result, err := stmt.Exec(input.Name, input.Email, input.Phone, input.Place, input.References, resumeURL, input.JobTitle, input.Message, 1, time.Now(), time.Now()) - if err != nil { - log.Error(err) - return err - } - - responseID, err := result.LastInsertId() - if err != nil { - log.Error(err) - return err - } - _, err = query.Exec(responseID, 1, 0, false, time.Now(), time.Now()) if err != nil { log.Error(err) diff --git a/jobs/jobs_test.go b/jobs/jobs_test.go index 742569bc7..9ed720eda 100644 --- a/jobs/jobs_test.go +++ b/jobs/jobs_test.go @@ -30,11 +30,11 @@ func TestInit(t *testing.T) { } func TestGetAllJobs(t *testing.T) { + utils.TruncateTables(testDB) err = utils.CreateTables(testDB) if err != nil { t.Errorf("Error in initializing test DB: %v", err) } - utils.TruncateTables(testDB) utils.PrepareTablesData(testDB) engine := gin.New() engine.GET("/api/careers", repo.Careers) diff --git a/leave/go.mod b/leave/go.mod index fc6e7610c..e08f52fbd 100644 --- a/leave/go.mod +++ b/leave/go.mod @@ -42,6 +42,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/leodido/go-urn v1.2.4 // indirect + github.com/lib/pq v1.2.0 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/notification/go.mod b/notification/go.mod index e7d1ef549..1520e9363 100644 --- a/notification/go.mod +++ b/notification/go.mod @@ -27,7 +27,6 @@ require ( github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.0 // indirect - github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -40,6 +39,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/leodido/go-urn v1.2.4 // indirect + github.com/lib/pq v1.2.0 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/sitemap/go.mod b/sitemap/go.mod index 13709a46f..7b089d713 100644 --- a/sitemap/go.mod +++ b/sitemap/go.mod @@ -28,7 +28,6 @@ require ( github.com/go-playground/locales v0.14.0 // indirect github.com/go-playground/universal-translator v0.18.0 // indirect github.com/go-playground/validator/v10 v10.10.0 // indirect - github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/goccy/go-json v0.9.7 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -39,6 +38,7 @@ require ( github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/leodido/go-urn v1.2.1 // indirect + github.com/lib/pq v1.2.0 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/utils/go.mod b/utils/go.mod index d3182417d..0347de199 100644 --- a/utils/go.mod +++ b/utils/go.mod @@ -18,7 +18,6 @@ require ( require ( cloud.google.com/go/compute v1.7.0 // indirect cloud.google.com/go/recaptchaenterprise v1.3.1 // indirect - github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/go-cmp v0.5.8 // indirect @@ -26,6 +25,7 @@ require ( github.com/googleapis/enterprise-certificate-proxy v0.1.0 // indirect github.com/googleapis/gax-go/v2 v2.4.0 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/lib/pq v1.2.0 // indirect go.opencensus.io v0.23.0 // indirect golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect diff --git a/utils/test.go b/utils/test.go index 4d8656f32..c17890c03 100644 --- a/utils/test.go +++ b/utils/test.go @@ -64,7 +64,12 @@ func SetRequestHeaders(req *http.Request, headers map[string]interface{}, conten func TestDB() (*sqlx.DB, error) { - err := os.Setenv("DB_NAME", "website_admin_test") + err := os.Setenv("DB_ENV", "test") + if err != nil { + return nil, err + } + + err = os.Setenv("DB_NAME", "website_admin_test") if err != nil { return nil, err } @@ -75,21 +80,23 @@ func TestDB() (*sqlx.DB, error) { func CreateTables(db *sqlx.DB) error { - jobs := "CREATE TABLE IF NOT EXISTS `jobs` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,`title` varchar(255) NULL DEFAULT NULL,`summary` varchar(500) NULL DEFAULT NULL,`description` text NULL DEFAULT NULL,`button_name` varchar(225) NULL DEFAULT NULL,`qualification` varchar(225) NULL DEFAULT NULL,`employment_type` varchar(225) NULL DEFAULT NULL,`base_salary` int(11) NULL DEFAULT NULL,`experience` varchar(225) NULL DEFAULT NULL,`is_active` tinyint(1) NULL DEFAULT 0,`skills` text NULL DEFAULT NULL,`total_openings` int(11) NULL DEFAULT 1,`responsibilities` text NULL DEFAULT NULL, `icon_name` varchar(255) NULL DEFAULT NULL , `unique_id` varchar(255) NULL DEFAULT NULL, `seo_title` varchar(255) NULL DEFAULT NULL, `seo_description` text NULL DEFAULT NULL, `apply_seo_title` varchar(255) NULL DEFAULT NULL, `apply_seo_description` text NULL DEFAULT NULL, `index` int(10) NULL DEFAULT 0, `created_at` timestamp NULL DEFAULT NULL,`updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`))" + jobs := "CREATE TABLE IF NOT EXISTS jobs (id SERIAL PRIMARY KEY, title varchar, summary text, description text, button_name varchar, qualification varchar, employment_type varchar, base_salary int4, experience varchar, is_active bool DEFAULT false, created_at timestamptz DEFAULT CURRENT_TIMESTAMP, updated_at timestamptz DEFAULT CURRENT_TIMESTAMP, skills text, total_openings int4 DEFAULT 1, responsibilities text, icon_name int4, unique_id varchar NOT NULL, seo_title varchar, seo_description text, apply_seo_title varchar, apply_seo_description text, index int4 NOT NULL DEFAULT 0)" _, err := db.Exec(jobs) if err != nil { return err } - jobApplications := "CREATE TABLE IF NOT EXISTS `job_applications` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,`name` varchar(255) NULL DEFAULT NULL,`email` varchar(255) NULL DEFAULT NULL,`phone` varchar(255) NULL DEFAULT NULL,`place` varchar(255) NULL DEFAULT NULL,`reference` varchar(255) NULL DEFAULT NULL,`resumeURL` varchar(255) NULL DEFAULT NULL,`position` varchar(255) NULL DEFAULT NULL,`message` text NULL DEFAULT NULL,`status` int(10) NULL DEFAULT 1, `created_at` timestamp NULL DEFAULT NULL,`updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`))" + + jobApplications := "CREATE TABLE job_applications (id SERIAL PRIMARY KEY, name varchar NOT NULL, email varchar NOT NULL, phone varchar NOT NULL, place varchar, reference varchar, resumeurl varchar NOT NULL, position varchar NOT NULL, message text, status int4 NOT NULL DEFAULT 1, created_at timestamptz DEFAULT CURRENT_TIMESTAMP, updated_at timestamptz DEFAULT CURRENT_TIMESTAMP )" _, err = db.Exec(jobApplications) if err != nil { return err } - jobsApplicantStatus := "CREATE TABLE IF NOT EXISTS `job_applicant_statuses` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT, `applicant_id` int(10) unsigned NOT NULL DEFAULT 0, `status` int(10) NOT NULL DEFAULT 1, `index` int(10) NOT NULL DEFAULT 0, `rejection_with_mail` tinyint(1) NULL DEFAULT 0, `created_at` timestamp NULL DEFAULT NULL,`updated_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`) ,FOREIGN KEY (`applicant_id`) REFERENCES `job_applications` (`id`))" + + jobsApplicantStatus := "CREATE TABLE job_applicant_statuses (id SERIAL PRIMARY KEY,applicant_id int4 NOT NULL,status int4 NOT NULL DEFAULT 1,index int4 NOT NULL DEFAULT 0,rejection_with_mail bool DEFAULT false,created_at timestamptz DEFAULT CURRENT_TIMESTAMP,updated_at timestamptz DEFAULT CURRENT_TIMESTAMP)" _, err = db.Exec(jobsApplicantStatus) @@ -97,23 +104,29 @@ func CreateTables(db *sqlx.DB) error { return err } + jobsIcons := "CREATE TABLE job_icons ( id SERIAL PRIMARY KEY, name varchar, value varchar, createdAt timestamptz, updatedAt timestamptz)" + + _, err = db.Exec(jobsIcons) + + if err != nil { + return err + } + return nil } func TruncateTables(db *sqlx.DB) { - db.MustExec("SET FOREIGN_KEY_CHECKS = 0") // Disable foreign key checks - - db.MustExec("TRUNCATE TABLE jobs") - db.MustExec("TRUNCATE TABLE job_applications") - db.MustExec("TRUNCATE TABLE job_applicant_statuses") - - db.MustExec("SET FOREIGN_KEY_CHECKS = 1") // Enable foreign key checks + db.MustExec("DROP TABLE IF EXISTS jobs") + db.MustExec("DROP TABLE IF EXISTS job_applications") + db.MustExec("DROP TABLE IF EXISTS job_applicant_statuses") + db.MustExec("DROP TABLE IF EXISTS job_icons") } func PrepareTablesData(db *sqlx.DB) { - db.MustExec("INSERT INTO jobs(`id`, `title`, `summary`, `description`, `button_name`,`qualification`, `employment_type`, `base_salary`, `experience`, `is_active`, `skills`, `total_openings`, `responsibilities`, `icon_name`, `unique_id`, `seo_title`, `seo_description`, `apply_seo_title`, `apply_seo_description`, `created_at`, `updated_at`) VALUES(1, 'IOS Developer', 'We have an opening for a passionate iOS developer who can develop and maintain applications for iOS devices. As an iOS developer you will be a part of a highly agile team tasked with developing new features. If you love to tackle new challenges, we would love to meet you!', '

 Develop mobile applications (iOS: Swift)

\r\n', 'Apply', 'B.E/B.Tech/BCA/MCA/MSc IT degree in Computer Science, Engineering, or a related subject ', 'full_time', 15000 , '0-3 years', true, '', 1, '','fab fa-apple', 'ios-developer-a9b45f34-a1a5-419f-b536-b7c290925d6d', 'iOS developer jobs in surat at Canopas, Mobile developer jobs', 'Find iOS developer job in surat. If we hire you as an iOS developer, you will be responsible for designing and coding the base application, ensuring the quality, fixing bugs, maintaining the code, and implementing app updates.', 'Apply for iOS developer job in surat or mobile developer jobs in surat at canopas software', 'Apply for iOS developer job at Canopas and be part of a dynamic and versatile iOS app development team.', UTC_TIMESTAMP(), UTC_TIMESTAMP())") - db.MustExec("INSERT INTO job_applications(`id`, `name`, `email`, `phone`, `place`,`reference`, `resumeURL`, `position`, `message`, `status`, `created_at`, `updated_at`) VALUES(1, 'New Web Developer', 'developer@gmail.com', '1234567890', 'surat', 'From canopas', '', 'Web Developer from testing', 'I m a very good programer', '1',UTC_TIMESTAMP(), UTC_TIMESTAMP())") - db.MustExec("INSERT INTO job_applicant_statuses(`id`, `applicant_id`, `status`, `index`, `rejection_with_mail`, `created_at`, `updated_at`) VALUES(1, 1, 1, 0, 0, UTC_TIMESTAMP(), UTC_TIMESTAMP())") + db.MustExec("INSERT INTO jobs(id, title, summary, description, button_name,qualification, employment_type, base_salary, experience, is_active, skills, total_openings, responsibilities, icon_name, unique_id, seo_title, seo_description, apply_seo_title, apply_seo_description, created_at, updated_at) VALUES(1, 'IOS Developer', 'We have an opening for a passionate iOS developer who can develop and maintain applications for iOS devices. As an iOS developer you will be a part of a highly agile team tasked with developing new features. If you love to tackle new challenges, we would love to meet you!', '

 Develop mobile applications (iOS: Swift)

\r\n', 'Apply', 'B.E/B.Tech/BCA/MCA/MSc IT degree in Computer Science, Engineering, or a related subject ', 'full_time', 15000 , '0-3 years', true, '', 1, '',1, 'ios-developer-a9b45f34-a1a5-419f-b536-b7c290925d6d', 'iOS developer jobs in surat at Canopas, Mobile developer jobs', 'Find iOS developer job in surat. If we hire you as an iOS developer, you will be responsible for designing and coding the base application, ensuring the quality, fixing bugs, maintaining the code, and implementing app updates.', 'Apply for iOS developer job in surat or mobile developer jobs in surat at canopas software', 'Apply for iOS developer job at Canopas and be part of a dynamic and versatile iOS app development team.', current_timestamp, current_timestamp)") + db.MustExec("INSERT INTO job_applications(id, name, email, phone, place,reference, resumeURL, position, message, status, created_at, updated_at) VALUES(1, 'New Web Developer', 'developer@gmail.com', '1234567890', 'surat', 'From canopas', '', 'Web Developer from testing', 'I m a very good programer', '1',current_timestamp, current_timestamp)") + db.MustExec("INSERT INTO job_applicant_statuses(id, applicant_id, status, index, rejection_with_mail, created_at, updated_at) VALUES(1, 1, 1, 0, false, current_timestamp,current_timestamp )") + db.MustExec("INSERT INTO job_icons (id,name,value,createdAt,updatedAt) VALUES ('1','iOS','fab fa-apple',NULL,NULL);") } func PrepareTextFileFormData() (string, *bytes.Buffer) {