Commit Graph

42 Commits

Author SHA1 Message Date
Aravind Shankar
21a4dff993
cli(squash): add set_table_is_enum metadata type (close #4394) (#4395) 2020-04-14 16:39:41 +05:30
Aravind Shankar
53e4f994d2
cli: event trigger retry_conf support to squash (close #4296) (#4324) 2020-04-10 08:22:41 +05:30
Aravind
14b5d10dfb
cli: refactor ec to allow setting hge api headers (#4347) 2020-04-09 15:00:47 +05:30
Aravind Shankar
21b61af109
cli: allow customization of server api paths (close #4016) (#4174) 2020-04-08 16:29:21 +05:30
Aravind Shankar
325771e406
cli: remove migration files if api returns error (close #4312) (#4319)
When using console from CLI and a migration is created, the files are written first and an API call is made to Hasura to execute that migration. There was a bug which caused this file to remain when the API call to Hasura failed. This commit fixes the bug by deleting the files if Hasura API call fails and propagates the error to console.
2020-04-08 10:54:47 +05:30
Aravind
de41438e8a
cli: refactor console command (#4150) 2020-04-07 14:53:20 +05:30
Aravind Shankar
41757b5f7f
cli: fix parse error returned on console api (close #4126) (#4152) 2020-03-25 16:12:39 +05:30
Aravind Shankar
89b6ce86ca
cli: misc fixes related to actions (#3942) 2020-02-25 12:16:11 +05:30
Aravind Shankar
bb63d7e60e
cli: allow managing actions (#3859)
Co-authored-by: Rishichandra Wawhal <rishichandra.wawhal@gmail.com>
Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com>
Co-authored-by: Aravind <aravindkp@outlook.in>
Co-authored-by: Anon Ray <ecthiender@users.noreply.github.com>
Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
2020-02-24 21:44:46 +05:30
Aravind
c258fa75cb
cli: add --goto flag in hasura migrate apply (close #2689) (#3715)
* cli: add --goto <version> flag to migrate command

* cli: fix error encoutered in goto, when on version -1

* do down migrations one step down

* reorganize code

* in case of up "gotos" make sure that all previous migration in migration chain are applied

* modify readUp and readDown functions to account for --goto use case

* refactor to clean up and adopt a better implementation addressing the comments

* remove empty error handling step

* return ErrNoChange when no migrations were applied

* respect m.stop() can panic so place conditional cases after that and add a couple other small fixes

* fix bug caused by early checking of versions

* fix to add migration_mode and nil version check

* add some more examples for migrate apply command

Co-authored-by: Aravind Shankar <face11301@gmail.com>
Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
2020-02-03 12:33:32 +05:30
Aravind Shankar
bf98f15dcf cli(fix): execute down migration in the correct order (#3625) 2020-01-06 15:21:00 +05:30
Rahul Verma
c6ab1014af cli(fix): better error handling on non-json api responses (clos… (#3104)
Co-authored-by: Rahul Verma <51950008+rahulverma283@users.noreply.github.com>
Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
2019-12-27 16:28:36 +05:30
Aravind Shankar
337403d532 cli(fix): squash command not adding the last down (close #3401) (#3569)
Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
2019-12-27 11:35:20 +05:30
Pradeep Murugesan
dece69c5a9 cli: add commands to manage inconsistent metadata (close #2766) (#2973)
Co-authored-by: Aravind Shankar <face11301@gmail.com>
Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
2019-12-25 14:03:06 +05:30
Rakesh Emmadi
421a182f64 export metadata without nulls, empty arrays & default values (#3393)
* export metadata without nulls, empty arrays
* property tests for 'ReplaceMetadata' using QuickCheck
-> Derive Arbitrary class for 'ReplaceMetadata' dependant types

* reduce property test cases number to 30
QuickCheck generates the `ReplaceMetadata` value really large
for higher number test cases. Encoded JSON for such values is large and
consumes more memory. Thus, CI is giving up while running property
tests.

* circle-ci: Add property tests as saperate job
* add no command mode to tests
* add yaml.v2 to go mod
* remove indirect comment for yaml.v2 dependency
2019-12-14 00:47:38 -06:00
Euler
56a217bbaa add name to migrate status response (close #2376) (#3109) 2019-11-28 17:06:16 +05:30
Aravind Shankar
980c65dbe2 cli(migrations): new folder structure and squash (#3072)
### Description
This PR introduces three new features:

- Support for a new migrations folder structure.
- Add `squash` command in preview.
- ~List of migrations on the Console and ability to squash them from console.~

#### New migrations folder structure

Starting with this commit, Hasura CLI supports a new directory structure for migrations folder and defaults to that for all new migrations created. 

Each migration will get a new directory with the name format `timestamp_name` and inside the directory, there will be four files:

```bash
└── migrations
    ├── 1572237730898_squashed
    │   ├── up.sql
    │   ├── up.yaml
    │   ├── down.yaml
    │   └── down.sql
```

Existing files old migration format `timestamp_name.up|down.yaml|sql` will continue to work alongside new migration files.

#### Squash command

Lots of users have expressed their interest in squashing migrations (see #2724 and #2254) and some even built [their own tools](https://github.com/domasx2/hasura-squasher) to do squash. In this PR, we take a systematic approach to squash migrations.

A new command called `migrate squash` is introduced. Note that this command is in **PREVIEW** and the correctness of squashed migration is not guaranteed (especially for down migrations). From our tests, **it works for most use cases**, but we have found some issues with squashing all the down migrations, partly because the console doesn't generate down migrations for all actions.

Hence, until we add an extensive test suite for squashing, we'll keep the command in preview. We recommend you to confirm the correctness yourself by diffing the SQL and Metadata before and after applying the squashed migrations (we're also thinking about embedding some checks into the command itself).

```bash
$ hasura migrate squash --help
(PREVIEW) Squash multiple migrations leading upto the latest one into a single migration file

Usage:
  hasura migrate squash [flags]

Examples:
  # NOTE: This command is in PREVIEW, correctness is not guaranteed and the usage may change.

  # squash all migrations from version 1572238297262 to the latest one:
  hasura migrate squash --from 1572238297262

Flags:
      --from uint             start squashing form this version
      --name string           name for the new squashed migration (default "squashed")
      --delete-source         delete the source files after squashing without any confirmation
```

### Affected components 
<!-- Remove non-affected components from the list -->

- CLI

### Related Issues
<!-- Please make sure you have an issue associated with this Pull Request -->
<!-- And then add `(close #<issue-no>)` to the pull request title -->
<!-- Add the issue number below (e.g. #234) -->
Close #2724, Close #2254, 

### Solution and Design
<!-- How is this issue solved/fixed? What is the design? -->
<!-- It's better if we elaborate -->

For the squash command, a state machine is implemented to track changes to Hasura metadata. After applying each action on the metadata state, a list of incremental changes is created.

### Steps to test and verify
1. Open console via cli and create some migrations.
2. Run `hasura migrate squash --from <version>`

### Limitations, known bugs & workarounds
<!-- Limitations of the PR, known bugs and suggested workarounds -->

<!-- Feel free to delete these comment lines -->
- The `squash` command is in preview
- Support for squashing from the console is WIP
- Support for squashing migrations that are not committed yet is planned.
- Un-tracking or dropping a table will cause inconsistent squashed down migration since console doesn't generate correct down migration.
- If cascade setting is set to `true` on any of the metadata action, generated migration may be wrong
2019-10-31 07:51:15 +05:30
Aravind Shankar
5f3294f4a0 optimise migrate api for console on cli (#2895) 2019-09-18 11:06:16 +05:30
Aravind Shankar
b39d7b977b check for empty response on migration settings (#2877)
(close #2872) (close #2862)
2019-09-16 14:20:46 +05:30
Aravind Shankar
c17bf2f94b create down migration when a column is dropped (close #2291) (#2385) 2019-06-26 18:42:44 +05:30
Shahidh K Muhammed
71cf017197 add an api to dump postgres schema (close #1939) (#1967) 2019-04-30 14:04:08 +05:30
Aravind Shankar
f147f6d6a6 improve error messages for metadata apply (close #1877) (#1895) 2019-04-03 12:27:59 +05:30
Aravind Shankar
040bef2fd5 add options to create migration from files from sql and server (close #1699) (#1761) 2019-03-18 22:10:04 +05:30
Aravind Shankar
c64a83f073 display error message for invalid migration file (fix #1224) (#1238) 2019-01-04 15:15:54 +05:30
Aravind Shankar
56dbc59822 better error messages for duplicate migration versions (close #1148) (#1157) 2018-12-04 10:03:03 +05:30
Aravind Shankar
6d2fd1db0d added support for file information in hasuradb driver (close #1136) (#1143) 2018-12-03 16:50:53 +05:30
Abilash Menon
0993740786 add reload metadata command to the cli (close #722) (#725) 2018-10-16 11:55:30 +05:30
Daniel P
b91704e3ca fix typos is multiple files (#728) 2018-10-15 12:29:51 +05:30
Aravind Shankar
396a2ccf8d change hasuradb url format, export some migrate functions (#294)
* fix migrate to use headers in query params

* export executeMigrations and PrintStatus
2018-08-22 00:07:47 +05:30
Aravind Shankar
75dbe35a21 create down migrations for actions from console (close #164) (#173) 2018-07-20 16:01:33 +05:30
Aravind Shankar
80c1994dc2 inserts into schema_migration only once per version (fix #127) (#128) 2018-07-12 19:54:46 +05:30
Aravind Shankar
6a20784b95 move metadata.yml file inside migrations folder, fix #122 (#125)
metadata.yaml will be present inside migrations folder
2018-07-12 18:22:25 +05:30
Aravind Shankar
268f0856d0 go vet cli code (#110) 2018-07-11 17:43:31 +05:30
Aravind Shankar
186340c156 fix #96, when access-key is set, cli should use it to contact api (#100) 2018-07-11 14:58:53 +05:30
Aravind Shankar
1bff452cb4 handle server endpoints that contains a url path (#64) 2018-07-09 19:17:38 +05:30
Aravind Shankar
1998e211af cli: update tests (#47)
* remove docker from migrate cmd test

* export migration status

* [cli] add fake writer for spinner

* Update console.go

* Update migrate_test.go
2018-07-06 10:36:27 +05:30
Aravind Shankar
260d565e6e cli: tests for metadata commands (#18)
* [cli] added urlPrefix, consoleMode

* [cli] fix: down=all should throw error if down migration is missing

* [cli] added tests for metadata
2018-06-29 15:32:33 +05:30
Aravind Shankar
59dd23cd17 [migrate status] fix: no migration files message when there are no migration files (#1)
```
$ hasura migrate status
VERSION  SOURCE STATUS  DATABASE STATUS
```
2018-06-28 14:08:47 +05:30
Aravind Shankar
048c067fa1 [cli] add tests for migrate commands (#9) 2018-06-28 14:06:57 +05:30
Shahidh K Muhammed
6d0d75fbe3
[cli] add comments (#4)
Especially for godoc
2018-06-28 14:06:25 +05:30
Shahidh
8e41d75aa3 refactor most of the code 2018-06-26 21:39:32 +05:30
Shahidh
f7409ef2eb
add hasura cli package 2018-06-24 19:10:48 +05:30