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

[RND-698] Postgresql insert/get #340

Merged
merged 3 commits into from
Jan 17, 2024
Merged

[RND-698] Postgresql insert/get #340

merged 3 commits into from
Jan 17, 2024

Conversation

bradbanister
Copy link
Contributor

No description provided.

bradbanister and others added 2 commits January 16, 2024 19:35
[RND-696] Schema validation

[RND-696] prove overposts can be removed

[RND-698] add postgresql insert and get support
@bradbanister bradbanister marked this pull request as ready for review January 17, 2024 01:38
@bradbanister
Copy link
Contributor Author

Requires Postgres with a "MeadowlarkNet" database, and hardcoded postgres/abcdefgh1! credentials (Gave up on getting .env loading working)

@stephenfuqua
Copy link
Contributor

Requires Postgres with a "MeadowlarkNet" database, and hardcoded postgres/abcdefgh1! credentials (Gave up on getting .env loading working)

appSettings file is the way to go for .NET applications. There are also methods for reading environment variables to override the appSettings file. reference

public static class Db
{
// TODO: Get .env loading working
private static readonly string connectionString = "Server=localhost;Port=5432;User Id=postgres;Password=abcdefgh1!;Database=MeadowlarkNet;";
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll end up using a very different pattern for injecting connectionStrings, likely using Admin API 2.0 as our inspiration.

{
// Note: ProjectName and ResourceName have been validated against the ApiSchema, so SQL injection is not a concern here
string schemaName = resourceInfo.ProjectName.Value.Replace("-", "");
string tableName = resourceInfo.ResourceName.Value.Replace("-", "");
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need to have an in-depth conversation as a team and community about whether to build the tables in MetaEd, deploy at runtime this way, or have a C# app with this same type of code that can run at deploy time.


var commandText = $@" INSERT INTO {schemaName}.{tableName}
(document_uuid, project_name, resource_name, resource_version, is_descriptor, edfi_doc)
VALUES ($1, $2, $3, $4, $5, $6)";
Copy link
Contributor

Choose a reason for hiding this comment

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

All good and makes sense. We'll need to make sure we have some robust injection attempts in unit testing.

* Simple only-once guard for a function with no parameters
*/
public static Action Once(Action fn){
var called = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll want to lock this for thread safety.

@@ -9,7 +9,8 @@
<ItemGroup>
<PackageReference Include="JsonSchema.Net" Version="5.5.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="DotNetEnv" Version="3.0.0" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove, since .env loading is not in use.

Copy link
Contributor

Choose a reason for hiding this comment

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

Forgot about my own comment when merging, oh well.

<ItemGroup>
<None Include=".env">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove, since .env loading is not in use.

@stephenfuqua stephenfuqua merged commit 889fbd4 into main Jan 17, 2024
1 check passed
@stephenfuqua stephenfuqua deleted the RND-698 branch January 17, 2024 14:58
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.

2 participants