Commit Graph

66 Commits

Author SHA1 Message Date
Jannik Clausen
7017cbc898 dialect/sql/schema: file based type store (#2644)
* dialect/sql/schema: file based type store

This PR adds support for a file based type storage when using versioned migrations. The file called `.ent_types` is written to the migration directory alongside the migration files and will be kept in sync for every migration file generation run.

In order to not break existing code, where the type storage might differ for different deployment, global unique ID mut be enabled by using a new option. This will also be raised as an error to the user when attempting to use versioned migrations and global unique ID.

Documentation will be added to this PR once feedback on the code is gathered.

* apply CR

* fix tests

* change format of types file to exclude it from atlas.sum file

* docs and drift test

* apply CR
2022-06-15 16:10:15 +02:00
Jannik Clausen
bfa9c963cb dialect/sql/schema: introduce type store interface (#2636)
This will allow us to store information about pk ranges allocated per type in a different location thant the database. This is useful for deterministic pk range computation for things like generating atlas.hcl out of the Ent schema.
2022-06-10 10:08:33 +02:00
Jannik Clausen
4142108d62 doc/website/blog: external tools and sum file (#2489)
* doc/website/blog: external tools and sum file

* Apply suggestions from code review

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>

* doc/website/blog: apply CR

* Apply suggestions from code review

Co-authored-by: Hila Kashai <73284641+hilakashai@users.noreply.github.com>

* doc/website/blog: minor fixes

* doc/website/blog: invoke atlas command by calling go run

* doc/website/blog: It's-a me, Jannik!

* Apply suggestions from code review

Co-authored-by: Rotem Tamir <rotemtamir@gmail.com>

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
Co-authored-by: Hila Kashai <73284641+hilakashai@users.noreply.github.com>
Co-authored-by: Rotem Tamir <rotemtamir@gmail.com>
2022-05-09 15:23:51 +02:00
MasseElch
12b6659c72 dialect/sql/schema: respect sumfile when present and do not operate on checksum mismatch (#2522) 2022-05-05 10:43:20 +02:00
MasseElch
c1175719a2 dialect/sql/schema: option to enable atlas sum file (#2470)
* dialect/sql/schema: option to enable atlas checksum file

* entc/integration/migrate: add integration tests for versioned migrations

* entc/integration/migrate: apply CR
2022-04-13 21:36:57 +02:00
Charles Ge
e463cbca55 init db version before executing diff (#2440)
What's the problem: Under versioned migration on MySQL 8.0, unique string field would be generated as type varchar(191) instead of varchar(255). This is because in generating migration files by NamedDiff(), sqlDialect's init() method is not called. 

Further concern: For init() function, MySQL and Postgres's implementation checks the database version which is what I want. But SQLite's implementation checks the foreign_keys support. So I think there might be a better may to check the database version before doing Diff().
2022-04-06 09:43:13 +02:00
MasseElch
db1617bb29 dialect/sql/schema: upgrade atlas and disable sum file creation (#2400)
* dialect/sql/schema: upgrade atlas and disable sum file creation

* dialect/sql/schema: linter
2022-03-15 17:40:56 +01:00
MasseElch
2853afc1dc dialect/sql/schema: add method to create a named versioned migration … (#2385)
* dialect/sql/schema: add method to create a named versioned migration file

* doc/md: documentation for named versioned migrations

* entc/gen/template/dialect/sql/feature: add NamedDiff method to create named versioned migration files

* all: go generate

* doc/md: apply CR
2022-03-10 16:40:57 +01:00
Ariel Mashraki
78a0fd9716 schema/field: expose RType.Implements method (#2379)
Also, add both (T) and (*T) methods for RType
2022-03-07 22:33:50 +02:00
Huy TQ
ddddc1d92a dialect/sql/schema: add name to versioned migration files (#2375)
* add name to versioned migration files

* Skip writing migration files if the plan has no changes
2022-03-07 10:18:07 +01:00
Ariel Mashraki
3aab4d91c2 all: update atlasgo.io to latest (#2376) 2022-03-04 22:53:37 +02:00
MasseElch
0239daca7b dialect/sql/schema: versioned migrations (#2337)
* dialect/sql/schema: fix go doc

* all: update atlas

* dialect/sql/schema: diff connected DB and defined schema and write changes to migration file

* dialect/sql/schema: use migration directory and formatter directly instead of a planner

* all: update atlas

* cmd: add command to create a new migration file

* entc/gen: generate main.go with migrate diff example

* all: regenerate

* cmd/internal/base: make linter happy

* all: support Go 1.16 in versioned migrations main.go

* entc/gen: put versioned migrations behind feature flag

* all: regenerate

* cmd/ent: driver-prefixed dsn in migrate diff command

* cmd/internal/base: remove prefix from migrate import

* cmd/internal/base: use cobra.CheckErr

* cmd: remove diff command

* entc/gen/template/dialect/sql/feature: remove generated main.go

* all: rebase on master and go mod tidy

* all: regenerate
2022-02-21 12:15:17 +02:00
Ariel Mashraki
60e03285d0 dialect/sql/schema: hello ariga.io/atlas (#2279) 2022-01-20 17:20:50 +02:00
Ariel Mashraki
6848f3fc7b dialect/sql/schema: do not sort primary-key columns before diff (#2254)
PKs are indexes and therefore, the order does matter.
Thanks to ariga.io/atlas we found this issue.
2022-01-09 15:37:21 +02:00
Mehmet Yılmaz
4d01a56b8d dialect/sql/schema: allow adding DEFAULT to columns on migration #1758 (#2199)
* add feature to SET DEFAULT value when add new default value to a existing column

* refactoring unit tests

* correct misspells

* code review refactors

* refactors

* Update dialect/sql/schema/postgres.go

* Update dialect/sql/schema/postgres.go

* Update dialect/sql/schema/postgres.go

* Update dialect/sql/schema/postgres.go

* Update dialect/sql/schema/postgres.go

Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
2021-12-20 11:29:07 +02:00
Ariel Mashraki
14cba0abb6 dialect/sql/schema: make Field.Unique and Index.Unique equal (#2004)
This will allow moving from:

	field.String(c).Unique()

To:

	index.Field(c).Unique()

And vice versa
2021-10-03 16:20:28 +03:00
Ariel Mashraki
397b3e984d dialect/sql/schema: setup tables before execute hooks 2021-08-04 21:43:00 +03:00
Ruben de Vries
1ea718f7bf dialect/sql/schema: add support for postgres and mysql numeric and decimal types in migrations (#1721)
* improve error message when failing to generate changeset

* support migrations for postgres and mysql numeric fields
2021-07-16 13:57:53 +03:00
Ariel Mashraki
66871c9806 dialect/sql/schema: add support for index prefixes in mysql 2021-06-09 22:52:31 +03:00
Ariel Mashraki
fd1f2df150 dialect/sql/schema: add support for pg arrays in migration 2021-04-14 14:25:28 +03:00
Ariel Mashraki
b4ad29f7f3 dialect/sql/schema: fix postgres index migration (#1351)
Fix PostgreSQL index migration when table_name = type_name.
Closed #1344
2021-03-18 22:29:39 +02:00
Matthew Gabeler-Lee
c53b45ddb0 all: use %w instead of %v to wrap errors (#1275)
* all: use %w instead of %v for nested errors with fmt.Errorf

* all: update generated code to use %w instead of %v for error wrapping
2021-03-03 20:05:33 +02:00
Ariel Mashraki
dd4792f5b3 go: rename module from github.com/facebook/ent => entgo.io/ent (#1226) 2021-02-02 23:03:04 +02:00
Ariel Mashraki
cc8da8fbf7 dialect/sql/schema: schema match from predicate 2021-01-18 12:38:39 +02:00
Ariel Mashraki
cfb8f5c4a9 dialect/sql/schema: minor style changes (#1152) 2021-01-07 20:37:47 +02:00
Ruben de Vries
a9c39bb952 dialect/sql/schema: add migration hooks (#1150) 2021-01-07 20:23:01 +02:00
Ariel Mashraki
faa54f5e79 Merge branch 'master' of https://github.com/day-dreams/ent into day-dreams-master 2020-10-21 12:31:11 +03:00
kakaxizhang
63421aa9ad dialect/sql/schema: optimize code and add website documents (#748) 2020-10-12 16:08:02 +08:00
day-dreams
90c3d50c39 fix: fix comment lint error 2020-09-20 17:02:04 +08:00
day-dreams
1f37dad827 fix: fix comment lint error 2020-09-20 16:56:36 +08:00
day-dreams
4582ed0f2a dialect/sql/schema: use withForeighKeys() instead of withForeighKeysDisable(), and add unit tests () (#748) 2020-09-20 16:49:47 +08:00
Ariel Mashraki
1348df349f dialect/sql/schema: disable fixture in default migration (#753) 2020-09-13 11:13:02 +03:00
day-dreams
54028de04f dialect/sql/schema: add MigrateOption 'WithForeighKeysDisable' (#748) 2020-09-13 01:50:37 +08:00
Ariel Mashraki
fd0a7f9f02 all: facebookincubator/ent => facebook/ent (#660)
ent repository is going to be migrated to facebook organization
2020-08-18 11:05:08 +03:00
Ariel Mashraki
33e4eb3a52 dialect/sql/schema: change id type of ent_types table to be unsigned (#612) 2020-07-16 20:07:37 +03:00
Ariel Mashraki
55c48a7ef8 dialect/sql/schema: minor style change (#557) 2020-06-17 23:12:03 +03:00
Ariel Mashraki
997a060043 dialect/sql/schemma: fail if column type is invalid (#486) 2020-05-11 14:20:35 +03:00
Ariel Mashraki
2208b243db dialect/sql/schema: initial work for incremental migration (#428)
This is a WIP PR and should be ignored this moment.
It's based on PR #221 created by Erik Hollensbe (He should
get his credit for his work before we land this).
2020-04-12 19:12:33 +03:00
Ariel Mashraki
b1eb999097 dialect/sql/schema: comment changes (#415) 2020-03-31 22:51:50 +03:00
Ariel Mashraki
320b9caf61 dialect/sql/schema: add option to skip fixture when it's irrelevant (#350) 2020-02-16 18:17:58 +02:00
Ariel Mashraki
26440c2bc9 dialect/sql/schema: setrange on custom column name of pks (#333) 2020-02-09 09:41:26 +02:00
Ariel Mashraki
c0c0d2ae5c dialect/sql/schema: verify and fix mysql auto-increment on reset (#329) 2020-02-06 19:36:23 +02:00
Ariel Mashraki
b4255998bf entc/gen: change name format for edge fks (#286)
* entc/gen: change name format for edge fks

* dialect/sql/schema: add fixture support for mysql and postgres

* sql/dialect: merge fkcolumn queries to one for the 2 dialects
2020-02-03 15:41:55 +02:00
Ariel Mashraki
6819c01906 dialect/sql: allow nil values for exec commands (#313)
In most cases, the sql.Result is not needed.
2020-01-22 22:43:45 +02:00
Ariel Mashraki
7fc3689027 dialect/sql/schema: add prepare option to mysql dialect 2020-01-01 19:11:20 +02:00
Ariel Mashraki
6bb834612c dialect/sql/schema: drop unique constraint on pg migration
Fixes #235
2019-12-15 18:52:05 +02:00
Ariel Mashraki
a5e4a9cf54 dialect/sqlscan: add ScanInt64 to be used by sqlgraph
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/213

Reviewed By: alexsn

Differential Revision: D18763694

fbshipit-source-id: 890b35fcc2a28914b276ce65477788b4ddaeebf9
2019-12-03 01:44:48 -08:00
Ariel Mashraki
0fc310e600 sql/dialect/schema: ignore foreign-keys in index dropping
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/188

Reviewed By: alexsn

Differential Revision: D18676877

fbshipit-source-id: 0babe457edadfa46dcbc7c7478d4468c48f84361
2019-11-24 05:32:22 -08:00
Ariel Mashraki
d5c111b35a dialect/sql/schema: univerdal id support for postgres
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/122

Reviewed By: alexsn

Differential Revision: D18113754

fbshipit-source-id: 1050f0c2b823db6ba1bc37c36f6749cfcffa982d
2019-10-24 08:45:09 -07:00
Ariel Mashraki
7f598f34a2 dialect/sql/schema: fix constraint symbol size for postgres
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/121

Reviewed By: alexsn

Differential Revision: D18113304

fbshipit-source-id: 80d4c65323eb2613fbb9ab47754b1e70b42b1b15
2019-10-24 08:45:09 -07:00