Skip to content

Conversation

carlosms
Copy link
Contributor

This commit adds the functionality for the import tool (#4).
A pending commit will add the same options to the export tool (#5)

The basic change is that arguments can now be:
sqlite:///path/to/db.db
postgresql://user:password@host:port

// With checkExisting it will fail if the DB does not exist
func Open(connection string, checkExisting bool) (DB, error) {
sqliteReg := regexp.MustCompile(`^sqlite://(.+)$`)
psReg := regexp.MustCompile(`^postgres(ql)?:.+$`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are checking only for prefix, right?
Would it be easier to use string.HasPrefix?
and for sqlite to remove prefix you can use string.TrimPrefix

just a suggestion, up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like to use regexp if there is any excuse :D

Copy link
Contributor

@smacker smacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like much being too smart and trying to invent abstraction on top of different databases when people solved this problem multiple times already and better than we.

But the rest looks ok. Approve.

@carlosms
Copy link
Contributor Author

I don't like much being too smart and trying to invent abstraction on top of different databases when people solved this problem multiple times already and better than we.

I have to agree with you, this may not be most elegant approach. The tool started simple enough that I just went with pure sql. Then postgres had to be added, and the code was already there for sqlite so...

@carlosms carlosms requested review from bzz and dpordomingo January 24, 2018 15:46
@bzz bzz removed the review label Jan 25, 2018
stored in the assignments table.
Usage: export <path-to-origin.db> <path-to-destination.db>
Usage: export DSN DSN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is DSN better then DB_URL ?

Also related - the requirement on the UI level for export is:

  • input: url to point to inernal DB
  • output: path in the filesystem to sqlight DB

And viasurvesa for import.

I believe it has advantage of simplicity for this app the user, at the same time agility for its developers (choose any DB)

Could you please update it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo DSN is better. It's standard name for it. If I read DB_URL, I'm not sure what format should be used.
For other points 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 a good argument for using DSN for DB part also might be posting something like https://en.wikipedia.org/wiki/Data_source_name :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there even a wiki page for it! I just saw it across documentation of different drivers & tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bzz:

input: url to point to inernal DB
output: path in the filesystem to sqlight DB

Please confirm: you want the output argument to accept only sqlite:// strings, or do you want it to ask for a path? i.e.

  1. export postgresql://user:password@host:port sqlite:///path/to/db.db
  2. export postgresql://user:password@host:port /path/to/db.db

Copy link
Contributor

@bzz bzz Jan 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 in my opinion follows the right contract.
Import would be import /path/to/db.db postgresql://user:password@host:port

I guess this PR could also take care of doc update, after #29 is merged.

carlosms added a commit to carlosms/code-annotation that referenced this pull request Jan 26, 2018
Not yet implemented, but the commands will use
filepaths for the input and output DB, limited
to SQLite
See PR src-d#28: src-d#28 (comment)

Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Copy link
Contributor

@bzz bzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

"regexp"
"strings"

_ "github.com/lib/pq"
Copy link
Contributor

@bzz bzz Jan 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this PR adds a new dependency library.

As #33 is already merged, this means import/export tools should also use dep and thus adding a dependency would include modification of the .toml file, right?

I guess that might also imply updates for #29 on how import/export tools are built.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. I'll rebase from master and update dep.

carlosms added a commit to smacker/code-annotation that referenced this pull request Jan 29, 2018
Not yet implemented, but the commands will use
filepaths for the input and output DB, limited
to SQLite
See PR src-d#28: src-d#28 (comment)

Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Arguments can now be sqlite:///path/to/db.db or
postgresql://user:password@host:port

Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>

Add posgres DB option to the export command

Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Only for the "external" DB, internal can still be
sqlite:// or posgresql://

Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
@carlosms carlosms merged commit 3866118 into src-d:master Jan 29, 2018
dpordomingo pushed a commit that referenced this pull request Mar 26, 2018
add tests to src-d/ci itself
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.

4 participants