Commit Graph

61 Commits

Author SHA1 Message Date
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
Ariel Mashraki
88bfbc38df dialect/sql/schema: index builders per dialect
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/118

Reviewed By: alexsn

Differential Revision: D18092371

fbshipit-source-id: 02b85724b1e00d10c930112b9e2c8d07c8727216
2019-10-24 02:23:33 -07:00
Ariel Mashraki
c414cd9a82 dialect/sql/schema: alter column for postgres
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/117

Reviewed By: alexsn

Differential Revision: D18083914

fbshipit-source-id: a5f6993cfe9a260a84c0d4ab868e3e797b3a5776
2019-10-23 05:39:17 -07:00
Ariel Mashraki
2789257849 dialect/sql/schema: alter table for postgres
Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/115

Reviewed By: alexsn

Differential Revision: D18065988

fbshipit-source-id: a7d33bbebd63b01659bc5ba562ac85642dcd3d83
2019-10-22 12:55:36 -07:00
Ariel Mashraki
dff3067639 dialect/sql/schema: table creation tests for postgres
Reviewed By: alexsn

Differential Revision: D18059272

fbshipit-source-id: f93785378119dfa18be31fdfc969848ea6d9b782
2019-10-22 08:17:05 -07:00
Ariel Mashraki
6f5f42ab3c dialect/sql: dialect based builders (#1550)
Summary:
Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1550

Pull Request resolved: https://github.com/facebookincubator/ent/pull/84

This is still WIP and you should ignore this.

Reviewed By: alexsn

Differential Revision: D17854477

fbshipit-source-id: 2d19713c118adb31164b7a2781327e64c87db8d4
2019-10-13 07:03:11 -07:00