Skip to content
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

WIP: Add Database Migrations (And more features as a result) #963

Closed
wants to merge 9 commits into from

Conversation

akalongman
Copy link
Member

@akalongman akalongman commented Jun 7, 2019

In this PR added:

  • Laravel's Database Query Builder and Migrations QB Docs Migrations Docs
  • Laravel's Service Container CI Docs
  • DotEnv Integration (and the possibility to create cacheable config files like Laravel's config)
  • Possibility to create CLI Commands like php telegram blabla

This brings only one BC change, PHP version should be >=7.1.3, but versions below 7.1 are already deprecated and not supported anymore.

@noplanman @jacklul please take a look, what do you think about the changes

How to test:

Pull this branch, copy .env.example to .env and write your settings, after run php telegram migrate

Two tables should be created, migrations for holding versions and users table which just copied from Laravel's default migration.

@@ -0,0 +1,65 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't these conflict with functions that might be defined by the underlying project already?
Especially as they are necessary for the functioning of the library.

Wouldn't it be better to have a dedicated Helpers class here?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can get rid of these helper functions, or wrap inside our namespace. I think its better than an abstract class with static functions

Copy link
Member

@noplanman noplanman Jun 10, 2019

Choose a reason for hiding this comment

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

or wrap inside our namespace

You mean as functions directly, instead of a class with static methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, like \Telegram\app().

Those helpers are for internal use, so in most cases, an user will not use those helpers

try {
$this->createDotenv($app)->load();
} catch (Exception $e) {
$this->writeErrorAndDie($e);
Copy link
Member

Choose a reason for hiding this comment

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

Does this make sense in respect of having this library integrated as part of an underlying project?
This literally forces the user to have a .env file (with that name!) in the current folder.

If I have a custom whatever.env that I load in my project, then the PHP Telegram Bot should just pick up those variables.

This bootstrapper should only be run when using the console command I think.

Copy link
Member Author

@akalongman akalongman Jun 10, 2019

Choose a reason for hiding this comment

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

If I have a custom whatever.env that I load in my project, then the PHP Telegram Bot should just pick up those variables.

How we should detect if user uses some custom whatever.env file?

Copy link
Member

Choose a reason for hiding this comment

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

Well, that's what the checks in the Telegram constructor are for, right?
If no API key is given, then an exception is thrown.

Same thing happens for the DB.

I think libraries that extend functionality of a project shouldn't require an own .env setup, but instead should define which environment variables are necessary for it to work.

Copy link
Member Author

Choose a reason for hiding this comment

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

@noplanman when user will create an instance of out Telegram/Application, our script will check the project's root for .env file.

I think libraries that extend functionality of a project shouldn't require an own .env setup, but instead should define which environment variables are necessary for it to work.

How to achieve this? Do not parse .env and just try to find variables in the $_ENV? Then user should parse .env file himself

return $_ENV['APP_CONFIG_CACHE'] ?? $this->bootstrapPath() . '/cache/config.php';
}

public function loadEnvironmentFrom($file): Application
Copy link
Member

Choose a reason for hiding this comment

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

This method can never be used, as the bootstrapping of the environment file happens in the constructor 🤔

How would one define a custom environment file as it is now?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am still thinking about that. How we can give the possibility to users to use some custom env file.

src/Bootstrap/SetupDatabase.php Show resolved Hide resolved
composer.json Show resolved Hide resolved
@noplanman
Copy link
Member

What about exporting all DB functionality to a separate package altogether?

I'm just wondering how best to handle custom .env files for an existing project without creating any dependency issues, i.e. main project uses different version of phpdotenv.

@hz61p1
Copy link

hz61p1 commented Dec 27, 2019

I am against the adoption of this PR, because it is a general-purpose package (CORE), and we must continue to develop it in this direction and not depend on implementation. If you need to integrate it into the framework, then create your own separate package for this, which will provide the necessary integration in a particular ecosystem. The same applies to creating your own framework based on this package.

@akalongman akalongman closed this Jan 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants