Skip to content

En/surreal migrations #1591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 25, 2025
Merged

En/surreal migrations #1591

merged 8 commits into from
Mar 25, 2025

Conversation

Umang01-hash
Copy link
Member

@Umang01-hash Umang01-hash commented Mar 20, 2025

Pull Request Template

Description:

// CreateNamespace creates a new namespace in the SurrealDB instance.
	CreateNamespace(ctx context.Context, namespace string) error

	// CreateDatabase creates a new database in the SurrealDB instance.
	CreateDatabase(ctx context.Context, database string) error

	// DropNamespace deletes a namespace from the SurrealDB instance.
	DropNamespace(ctx context.Context, namespace string) error

	// DropDatabase deletes a database from the SurrealDB instance.
	DropDatabase(ctx context.Context, database string) error

Example Migration

package migrations

import (
	"context"

	"gofr.dev/pkg/gofr/migration"
)

const createTable = `
DEFINE TABLE employee SCHEMAFULL;
`

const defineSchema = `
DEFINE FIELD id ON employee TYPE number ASSERT $value != NONE;
DEFINE FIELD name ON employee TYPE string;
DEFINE FIELD gender ON employee TYPE string;
DEFINE FIELD contact_number ON employee TYPE string;
DEFINE FIELD dob ON employee TYPE string;
DEFINE INDEX unique_id ON employee COLUMNS id UNIQUE;
`

func CreateDatabase() migration.Migrate {
	return migration.Migrate{
		UP: func(d migration.Datasource) error {
			surreal := d.SurrealDB
			ctx := context.Background()

			if _, err := surreal.Query(ctx, createTable, nil); err != nil {
				return err
			}

			if _, err := surreal.Query(ctx, defineSchema, nil); err != nil {
				return err
			}

			return nil
		},
	}
}

Results:

Screenshot 2025-03-20 at 4 36 27 PM

Checklist:

  • I have formatted my code using goimport and golangci-lint.
  • All new code is covered by unit tests.
  • This PR does not decrease the overall code coverage.
  • I have reviewed the code comments and documentation for clarity.

Thank you for your contribution!

@aryanmehrotra aryanmehrotra merged commit 34ccff0 into development Mar 25, 2025
17 checks passed
@aryanmehrotra aryanmehrotra deleted the en/surreal_migrations branch March 25, 2025 07:52
Umang01-hash added a commit that referenced this pull request Mar 25, 2025
* Bump github.com/redis/go-redis/v9 in the go_modules group (#1593)

* Bump github.com/redis/go-redis/v9 (#1592)

* Bump github.com/golang-jwt/jwt/v5 in the go_modules group (#1596)

* Bump github.com/golang-jwt/jwt/v5 (#1597)

* Moving pprof endpoint to metrics port (#1594)

* Bump google.golang.org/protobuf from 1.36.5 to 1.36.6 (#1606)

* Bump github.com/go-sql-driver/mysql from 1.9.0 to 1.9.1 (#1603)

* Bump google.golang.org/api from 0.226.0 to 0.227.0 (#1602)

* Bump modernc.org/sqlite from 1.36.1 to 1.36.2 (#1604)

* Bump github.com/redis/go-redis/extra/redisotel/v9 from 9.7.1 to 9.7.3 (#1605)

* Add migrations for surreal DB(#1591)

* add metrics for surrealDB (#1600)

* update linter to v1.64.0 (#1607)

* update and test linter v1.64

* remove unwanted code

---------

Co-authored-by: Aryan Mehrotra <aryanmehrotra2000@gmail.com>

* Adding Verification for JWT Claims (#1580)

Co-authored-by: Umang Mundhra <mundhraumang.02@gmail.com>
Co-authored-by: Aryan Mehrotra <aryanmehrotra2000@gmail.com>
Co-authored-by: @ccoVeille <3875889+ccoVeille@users.noreply.github.com>

* Fix: Dockerfile to deploy website build fail  (#1609)

* update release version to v1.36.0

---------

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Divya Darshana <98943137+coolwednesday@users.noreply.github.com>
Co-authored-by: Aryan Mehrotra <aryanmehrotra2000@gmail.com>
Co-authored-by: @ccoVeille <3875889+ccoVeille@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Migrations in SurrealDB
4 participants